Skip to content
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

fix(auth): dispatch signInWithRedirect error #12653

Merged
merged 6 commits into from
Dec 4, 2023

Conversation

israx
Copy link
Contributor

@israx israx commented Nov 29, 2023

Description of changes

In case of an oauth exception:

  • Web: Avoids Uncaught exception and dispatches a hub event
  • RN: throws an error and dispatches a hub event

Issue #, if available

Description of how you validated changes

created a sample app in web and validated that the library dispatches a signInWithRedirect_failure under the following circumstances:

  • responseType is code and there is an error returned from hostedUI
  • responseType is code and the oauth state is not valid
  • responseType is token and there is an error returned from hostedUI
  • responseType is token and the oauth state is not valid

PR was validated in RN with the same testing criteria as above.

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@israx israx requested review from a team as code owners November 29, 2023 17:22
@israx israx marked this pull request as draft November 29, 2023 17:22
Copy link
Contributor

@AllanZhengYP AllanZhengYP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change makes sense to me! Pending some more unit tests.

cshfang
cshfang previously approved these changes Nov 29, 2023
Copy link
Contributor

@cshfang cshfang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lgtm

packages/core/src/Hub/types/AuthTypes.ts Outdated Show resolved Hide resolved
const error = new AuthError({
message: errorMessage ?? 'An error has occurred during the oauth proccess',
name: AuthErrorCodes.OAuthSignInError,
recoverySuggestion: authErrorMessages.oauthSignInError.log,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@israx israx marked this pull request as ready for review November 30, 2023 21:10
@israx israx requested a review from a team as a code owner November 30, 2023 21:10
@israx israx force-pushed the signInWithRedirect-error branch 2 times, most recently from 5f7cb9b to 4c57fdd Compare November 30, 2023 21:24
Copy link
Contributor

@AllanZhengYP AllanZhengYP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thank you! @israx

@@ -116,6 +116,8 @@ export async function oauthSignIn({
const { type, error, url } =
(await openAuthSession(oAuthUrl, redirectSignIn, preferPrivateSession)) ??
{};
// This code will run in RN applications only as calling signInWithRedirect will
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think it's more relevant here to say that openAuthSession will resolve in RN

Comment on lines +134 to +135
// This code will run in RN applications only as calling signInWithRedirect will
// resolve the promise.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here

store.loadOAuthState().then(resp => {
savedState = resp;
});
async function validateState(state?: string | null): Promise<string> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Since this is now actually returning something, I would opt for a name that better reflects the new behavior. E.g. getValidatedState

@israx israx merged commit 271546d into aws-amplify:main Dec 4, 2023
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants