-
Notifications
You must be signed in to change notification settings - Fork 255
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
feat(clerk-js,localizations,shared,types): Prompt user to reset pwned… #3034
Conversation
🦋 Changeset detectedLatest commit: a95a202 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -135,6 +138,10 @@ export function _SignInFactorOne(): JSX.Element { | |||
}} | |||
onForgotPasswordMethodClick={resetPasswordFactor ? toggleForgotPasswordStrategies : toggleAllStrategies} | |||
onShowAlternativeMethodsClick={toggleAllStrategies} | |||
onPasswordPwned={() => { | |||
setIsPasswordPwned(true); | |||
toggleForgotPasswordStrategies(); |
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.
We could potentially also trigger the reset flow to start, but preferred to allow them to click it themselves.
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.
agreed
@@ -40,12 +41,13 @@ const usePasswordControl = (props: SignInFactorOnePasswordProps) => { | |||
: onShowAlternativeMethodsClick | |||
? onShowAlternativeMethodsClick | |||
: () => null, | |||
// onPasswordPwned, |
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.
Assumed I would need to include it here as were, but this causes the following error:
Warning: Unknown event handler property onPasswordPwned. It will be ignored.
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.
not sure why you need it here?
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.
Me neither :-D
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.
@desiprisg do we not need to export is like the other handlers?
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.
Seems like we don't need it, can we remove the comment ?
@@ -58,6 +60,7 @@ export const SignInFactorOnePasswordCard = (props: SignInFactorOnePasswordProps) | |||
const clerk = useClerk(); | |||
|
|||
const goBack = () => { | |||
card.setError(undefined); |
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.
This doesn't work, the error is not cleared.
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.
Never mind, this was not the correct location to do it.
@@ -83,6 +86,14 @@ export const SignInFactorOnePasswordCard = (props: SignInFactorOnePasswordProps) | |||
return clerk.__internal_navigateWithError('..', err.errors[0]); | |||
} | |||
|
|||
if (isPasswordPwnedError(err)) { | |||
if (onPasswordPwned) { | |||
card.setError({ ...err.errors[0], code: err.errors[0].code + '__sign_in' }); |
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.
Need to add a suffix to target the l10n key we want.
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.
I'd say just hardcode it here since the type will always be the same.
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.
Sure
7b91a29
to
8a2a243
Compare
@@ -83,6 +86,14 @@ export const SignInFactorOnePasswordCard = (props: SignInFactorOnePasswordProps) | |||
return clerk.__internal_navigateWithError('..', err.errors[0]); | |||
} | |||
|
|||
if (isPasswordPwnedError(err)) { | |||
if (onPasswordPwned) { | |||
card.setError({ ...err.errors[0], code: err.errors[0].code + '__sign_in' }); |
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.
I'd say just hardcode it here since the type will always be the same.
@@ -58,6 +60,7 @@ export const SignInFactorOnePasswordCard = (props: SignInFactorOnePasswordProps) | |||
const clerk = useClerk(); | |||
|
|||
const goBack = () => { | |||
card.setError(undefined); |
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.
Maybe we ignore undefined
? Or maybe there's a function to clear the error? Could you check the implementation?
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.
It worked when I moved it to the proper back handlers.
@@ -40,12 +41,13 @@ const usePasswordControl = (props: SignInFactorOnePasswordProps) => { | |||
: onShowAlternativeMethodsClick | |||
? onShowAlternativeMethodsClick | |||
: () => null, | |||
// onPasswordPwned, |
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.
not sure why you need it here?
@@ -135,6 +138,10 @@ export function _SignInFactorOne(): JSX.Element { | |||
}} | |||
onForgotPasswordMethodClick={resetPasswordFactor ? toggleForgotPasswordStrategies : toggleAllStrategies} | |||
onShowAlternativeMethodsClick={toggleAllStrategies} | |||
onPasswordPwned={() => { | |||
setIsPasswordPwned(true); | |||
toggleForgotPasswordStrategies(); |
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.
agreed
e98fd3d
to
2503592
Compare
2982469
to
f5198a2
Compare
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.
If we could also get a couple of tests in to make sure this functionality doesn't break in the future, that would be superb!
Edit: Was looking at a commit. Re-reviewing..
I have added 2 tests (phone + pwned, email + pwned), can you recommend more scenarios? |
@@ -40,12 +41,13 @@ const usePasswordControl = (props: SignInFactorOnePasswordProps) => { | |||
: onShowAlternativeMethodsClick | |||
? onShowAlternativeMethodsClick | |||
: () => null, | |||
// onPasswordPwned, |
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.
Seems like we don't need it, can we remove the comment ?
@@ -67,6 +67,10 @@ export function isUserLockedError(err: any) { | |||
return isClerkAPIResponseError(err) && err.errors?.[0]?.code === 'user_locked'; | |||
} | |||
|
|||
export function isPasswordPwnedError(err: any) { | |||
return isClerkAPIResponseError(err) && err.errors?.[0]?.code === 'form_password_pwned'; |
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.
How come we use the first error item ? Will this always be the case from FAPI ? I see that we are doing the same above, just asking tho.
… password at sign-in
0060707
to
a95a202
Compare
… password at sign-in
Description
If admin has enabled
password_settings.enforce_on_sign_in
and HIBP is enabled, then a password could potentially be detected as pwned at a subsequent sign-in.The API will respond with error code
form_password_pwned
, in which case we will show a corresponding error and show the alternative method list, prompting them to reset their password.Checklist
npm test
runs as expected.npm run build
runs as expected.Type of change