Skip to content

Commit f58ec73

Browse files
authored
feat(console): auto add forgot password methods for new sign-up (#7633)
1 parent 384b91b commit f58ec73

File tree

1 file changed

+39
-1
lines changed
  • packages/console/src/pages/SignInExperience/PageContent/SignUpAndSignIn/SignUpForm/SignUpIdentifiersEditBox

1 file changed

+39
-1
lines changed

packages/console/src/pages/SignInExperience/PageContent/SignUpAndSignIn/SignUpForm/SignUpIdentifiersEditBox/index.tsx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
AlternativeSignUpIdentifier,
3+
ForgotPasswordMethod,
34
SignInIdentifier,
45
type SignUpIdentifier,
56
type SignInExperience,
@@ -64,6 +65,42 @@ function SignUpIdentifiersEditBox({ signInExperience }: Props) {
6465
}
6566
}, [submitCount, trigger]);
6667

68+
/**
69+
* Append the forgot password methods based on the selected sign-up identifier.
70+
*/
71+
const appendForgotPasswordMethods = useCallback(
72+
(identifier: SignUpIdentifier) => {
73+
const forgotPasswordMethods = getValues('forgotPasswordMethods');
74+
const forgotPasswordMethodsSet = new Set(forgotPasswordMethods);
75+
76+
const newForgotPasswordMethods = [
77+
// Add email verification code if email-related identifier is added
78+
...((identifier === SignInIdentifier.Email ||
79+
identifier === AlternativeSignUpIdentifier.EmailOrPhone) &&
80+
!forgotPasswordMethodsSet.has(ForgotPasswordMethod.EmailVerificationCode)
81+
? [ForgotPasswordMethod.EmailVerificationCode]
82+
: []),
83+
// Add phone verification code if phone-related identifier is added
84+
...((identifier === SignInIdentifier.Phone ||
85+
identifier === AlternativeSignUpIdentifier.EmailOrPhone) &&
86+
!forgotPasswordMethodsSet.has(ForgotPasswordMethod.PhoneVerificationCode)
87+
? [ForgotPasswordMethod.PhoneVerificationCode]
88+
: []),
89+
];
90+
91+
if (newForgotPasswordMethods.length > 0) {
92+
setValue(
93+
'forgotPasswordMethods',
94+
[...(forgotPasswordMethods ?? []), ...newForgotPasswordMethods],
95+
{
96+
shouldDirty: true,
97+
}
98+
);
99+
}
100+
},
101+
[getValues, setValue]
102+
);
103+
67104
/**
68105
* Append the sign-in methods based on the selected sign-up identifier.
69106
*/
@@ -103,6 +140,7 @@ function SignUpIdentifiersEditBox({ signInExperience }: Props) {
103140
const onAppendSignUpIdentifier = useCallback(
104141
(identifier: SignUpIdentifier) => {
105142
appendSignInMethods(identifier);
143+
appendForgotPasswordMethods(identifier);
106144

107145
/**
108146
* If username is added as a sign-up identifier, we should check "Create your password" checkbox.
@@ -117,7 +155,7 @@ function SignUpIdentifiersEditBox({ signInExperience }: Props) {
117155
});
118156
}
119157
},
120-
[appendSignInMethods, setValue]
158+
[appendSignInMethods, appendForgotPasswordMethods, setValue]
121159
);
122160

123161
const options = useMemo<

0 commit comments

Comments
 (0)