-
Notifications
You must be signed in to change notification settings - Fork 21
feat: DAH-4337 Account Setting: Change Password Flow #3055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
1b5df0e
f76cf98
e1727b7
a1b2e2b
1234ab6
6e352a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PII More Details
Sampled Examples
To ignore this finding as an exception, reply to this conversation with If you'd like to ignore this finding in all future scans, add an exception in the .wiz file (learn more) or create an Ignore Rule (learn more). To get more details on how to remediate this issue using AI, reply to this conversation with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PII More Details
Sampled Examples
To ignore this finding as an exception, reply to this conversation with If you'd like to ignore this finding in all future scans, add an exception in the .wiz file (learn more) or create an Ignore Rule (learn more). To get more details on how to remediate this issue using AI, reply to this conversation with |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /* eslint-disable @typescript-eslint/unbound-method */ | ||
| import { t } from "@bloom-housing/ui-components" | ||
| import { Heading } from "@bloom-housing/ui-seeds" | ||
| import { useAuth, useSession, useUser } from "@clerk/clerk-react" | ||
| import React, { useContext, useEffect, useState } from "react" | ||
| import { useForm } from "react-hook-form" | ||
| import { useNavigate } from "react-router" | ||
| import UserContext from "../../authentication/context/UserContext" | ||
| import { useFeatureFlag } from "../../hooks/useFeatureFlag" | ||
| import AuthLayout from "../../layouts/AuthLayout" | ||
| import withAppSetup from "../../layouts/withAppSetup" | ||
| import { UNLEASH_FLAG } from "../../modules/constants" | ||
| import { AppPages, getMyAccountSettingsPath, getSignInPath } from "../../util/routeUtil" | ||
| import { ErrorSummaryBanner } from "./components/ErrorSummaryBanner" | ||
| import PasswordFieldset, { | ||
| passwordFieldsetErrors, | ||
| passwordSortOrder, | ||
| handleClerkPasswordErrors, | ||
| } from "./components/PasswordFieldset" | ||
| import { getErrorMessage } from "./components/util" | ||
| import { Banner, UpdateForm } from "./settings" | ||
| import "./styles/account.scss" | ||
|
|
||
| const ChangePasswordPage = () => { | ||
| const [loading, setLoading] = useState(false) | ||
| const [passwordBanner, setPasswordBanner] = useState(false) | ||
| const { profile } = useContext(UserContext) | ||
| const { user } = useUser() | ||
| const { session } = useSession() | ||
|
|
||
| const navigate = useNavigate() | ||
| const { | ||
| register, | ||
| formState: { errors }, | ||
| handleSubmit, | ||
| watch, | ||
| setError, | ||
| } = useForm({ mode: "onTouched" }) | ||
|
|
||
| const onSubmit = async (data: { password: string; currentPassword: string }) => { | ||
| setLoading(true) | ||
| const { password, currentPassword } = data | ||
|
|
||
| if (password === "" || !user || !session) { | ||
| setLoading(false) | ||
| return | ||
| } | ||
|
|
||
| try { | ||
| await session.startVerification({ level: "first_factor" }) | ||
| await session.attemptFirstFactorVerification({ | ||
| strategy: "password", | ||
| password: currentPassword, | ||
| }) | ||
|
|
||
| await user.updatePassword({ | ||
| currentPassword, | ||
| newPassword: password, | ||
| signOutOfOtherSessions: true, | ||
| }) | ||
| setPasswordBanner(true) | ||
| void navigate(getMyAccountSettingsPath()) | ||
| } catch (error) { | ||
| setError(...handleClerkPasswordErrors(error)) | ||
| } finally { | ||
| setLoading(false) | ||
| } | ||
| } | ||
| return ( | ||
| <AuthLayout title={t("accountSettings.changePassword")}> | ||
| <Banner | ||
| showBanner={passwordBanner} | ||
| className="mt-8" | ||
| message={t("accountSettings.accountChangesSaved")} | ||
| onClose={() => setPasswordBanner(false)} | ||
| /> | ||
| <ErrorSummaryBanner | ||
| errors={errors} | ||
| sortOrder={passwordSortOrder} | ||
| messageMap={(messageKey) => getErrorMessage(messageKey, passwordFieldsetErrors, true)} | ||
| /> | ||
| <UpdateForm | ||
| onSubmit={handleSubmit(onSubmit)} | ||
| loading={loading} | ||
| submitLabel={t("accountSettings.savePassword")} | ||
| > | ||
| <Heading priority={1} size="2xl"> | ||
| {t("accountSettings.changePassword")} | ||
| </Heading> | ||
| <PasswordFieldset | ||
| register={register} | ||
| errors={errors} | ||
| watch={watch} | ||
| email={profile?.email} | ||
| labelText={t("label.password")} | ||
| passwordType="accountSettings" | ||
| /> | ||
| </UpdateForm> | ||
| </AuthLayout> | ||
| ) | ||
| } | ||
|
|
||
| const ChangePassword = (_props: { assetPaths: unknown }) => { | ||
| const navigate = useNavigate() | ||
| const { isLoaded, isSignedIn } = useAuth() | ||
| const { profile, initialStateLoaded } = useContext(UserContext) | ||
| const { unleashFlag: clerkEnabled, flagsReady } = useFeatureFlag(UNLEASH_FLAG.CLERK_AUTH, false) | ||
|
|
||
| useEffect(() => { | ||
| if (!flagsReady) return | ||
| if (!clerkEnabled) { | ||
| void navigate(getSignInPath()) | ||
| return | ||
| } | ||
| if (!isLoaded) return | ||
| if (!isSignedIn) { | ||
| void navigate(getSignInPath()) | ||
| return | ||
| } | ||
| }, [flagsReady, clerkEnabled, isLoaded, isSignedIn, initialStateLoaded, profile, navigate]) | ||
|
|
||
| const ready = flagsReady && clerkEnabled && isLoaded && isSignedIn | ||
|
|
||
| if (!ready) { | ||
| return null | ||
| } | ||
|
|
||
| return <ChangePasswordPage /> | ||
| } | ||
|
|
||
| export default withAppSetup(ChangePassword, { | ||
| useFormTimeout: true, | ||
| pageName: AppPages.ChangePassword, | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| == react_component 'App', props: @change_password_props |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PII
More Details
Sampled Examples
To ignore this finding as an exception, reply to this conversation with
#wiz_ignore reasonIf you'd like to ignore this finding in all future scans, add an exception in the .wiz file (learn more) or create an Ignore Rule (learn more).
To get more details on how to remediate this issue using AI, reply to this conversation with
#wiz remediate