-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
chore(auth): add authenticated client side validation #12033
chore(auth): add authenticated client side validation #12033
Conversation
…uthenticated-validation
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.
minor thing to add
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.
aff0a0a
to
b3be14e
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.
Looks good, some nits
@@ -630,3 +633,19 @@ export function isMFATypeEnabled( | |||
if (!mfaTypes) return false; | |||
return mfaTypes.includes(mfaType); | |||
} | |||
|
|||
export async function isUserAuthenticated() { |
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.
Nit pick but the current name makes it sound like this behaves like a predicate (i.e. returns a bool to know if user is signed in).
export async function isUserAuthenticated() { | |
export async function assertUserNotAuthenticated() { |
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.
Yeah agree. Sounds more like a predicate. I changed it already. Thanks
…uthenticated-validation
fe68ddf
to
e33e7c7
Compare
let authUser: AuthUser | undefined; | ||
try { | ||
authUser = await getCurrentUser(); | ||
} catch (error) {} |
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.
Should we do something with this catch? Maybe log?
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.
good point. If getCurrentUser
throws it's because no tokens were found. So in the context of sign-in that is expected always. So logging something doesn't really help here.
To bad as this change made no longer possible to revalidate user password :( |
Description of changes
This PR adds client side validation for authenticated users that try to sign-in again.
Other changes:
Improve error messaging for users that call APIs that require the user to be authenticated.
Issue #, if available
Description of how you validated changes
tested change in a sample app, where I was able to get an error when trying to call sign-in while authenticated.
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.