aws-amplify / amplify-ui

Amplify UI is a collection of accessible, themeable, performant React (and more!) components that can connect directly to the cloud.
https://ui.docs.amplify.aws
Apache License 2.0
826 stars 272 forks source link

Browser crashes when refresh token is expired #1773

Closed ptaranto closed 2 years ago

ptaranto commented 2 years ago

Before creating a new issue, please confirm:

On which framework/platform are you having an issue?

React

Which UI component?

Authenticator

How is your app built?

NX/webpack

Please describe your bug.

After successful login with tokens saved in local storage, launching the app when the refresh token is expired the browser tab crashes.

I was able to breakpoint it and check that tokens in local storage are cleared by CognitoUser.js, dispatchAuthEvent('tokenRefresh_failure', error, "Failed to retrieve new token"); is called by AuthClass, then it gets lost when running a generator function in Auth.js

What's the expected behaviour?

user is redirected to the Authenticator login form

Help us reproduce the bug!

Code Snippet

https://codesandbox.io/s/zealous-star-xhj15y

import { Amplify } from "aws-amplify";
import { Authenticator, Flex } from "@aws-amplify/ui-react";
import "./styles.css";
import "@aws-amplify/ui-react/styles.css";

Amplify.configure({
  Auth: {
    region: "eu-west-1",
    userPoolId: "eu-west-1_POOLID",
    userPoolWebClientId: "POOL_ID",
    authenticationFlowType: "USER_PASSWORD_AUTH"
  }
});

export default function App() {
  return (
    <Flex justifyContent="center" alignItems="center" height="100vh">
      <Authenticator.Provider>
        <Authenticator>
          {(props) => {
            console.log(props.user);
            return (
              <>
                <p>{props.user.username}</p>
                <button onClick={props.signOut}>sign-out</button>
              </>
            );
          }}
        </Authenticator>
      </Authenticator.Provider>
    </Flex>
  );
}

Additional information and screenshots

libs in package.json: "@aws-amplify/ui-react": "2.13.0" "amazon-cognito-identity-js": "^5.2.8" "aws-amplify": "^4.3.19"

Notes:

ptaranto commented 2 years ago

cross-posting in amplify-js too https://github.com/aws-amplify/amplify-js/issues/9833

wlee221 commented 2 years ago

Hi @ptarnto, thanks for the detailed repro steps!

This is a duplicate of #1683 so I'll close this one and track progress in #1683. I'm looking into this issue now -- please expect an update by this week.

wlee221 commented 2 years ago

Hi @ptaranto, the fix PR has been merged and will be released later today. I'll let you know again after the release.

ptaranto commented 2 years ago

thanks @wlee221 , that's great, looking forward for the release

wlee221 commented 2 years ago

Update -- this has been released to

@aws-amplify/ui-angular@2.4.1
@aws-amplify/ui-react@2.16.1
@aws-amplify/ui-vue@2.4.1

Please let us know if the issue persists 🙏

ptaranto commented 2 years ago

@wlee221 thanks for the update and sorry for the late reply, the issue wasn't fixed in 2.16.1 but seems to be fixed in 2.17.0