Skip to content

Commit

Permalink
Dispose of ?code on error and success (aws-amplify#8166)
Browse files Browse the repository at this point in the history
Co-authored-by: Manuel Iglesias <[email protected]>
  • Loading branch information
ericclemmons and manueliglesias authored Aug 2, 2021
1 parent 8cfbe10 commit d4f8fe6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/auth/src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,17 @@ export class AuthClass {
return credentials;
} catch (err) {
logger.debug('Error in cognito hosted auth response', err);

// Just like a successful handling of `?code`, replace the window history to "dispose" of the `code`.
// Otherwise, reloading the page will throw errors as the `code` has already been spent.
if (window && typeof window.history !== 'undefined') {
window.history.replaceState(
{},
null,
(this._config.oauth as AwsCognitoOAuthOpts).redirectSignIn
);
}

dispatchAuthEvent(
'signIn_failure',
err,
Expand Down

0 comments on commit d4f8fe6

Please sign in to comment.