Amplify-js: current Session never expires

Created on 22 May 2018  路  3Comments  路  Source: aws-amplify/amplify-js

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
I have a React app which was built using the awsmobile cli.
In my App.ts I have this:

import { Auth } from 'aws-amplify';
...
  async componentDidMount() {
    try {
      if (await Auth.currentSession()) {
        const user = await Auth.currentAuthenticatedUser();
        store.dispatch(actionCreators.setAuthUser(user));
      } 
    } catch (e) {
      store.dispatch(actionCreators.setAuthState('unauthenticated'));
      if (e !== 'No current user') { 
        alert(e);
      }
    }
  }

Granted I have not seen much documentation on this so this it be the wrong approach, but my understanding is that Auth.currentSession will 'throw' if the session is invalid, which I thought would occur after 1 hour of inactivity, or when the browser closes. ( Again, cannot find good documentation on session details, so I might be wrong ).

However, if I load the app many hours after activity, or even a day later, it automatically logs me in.
I need some assistance on how to rectify this.
Thank you.

What is the expected behavior?

Session should be invalid.

current version is:

"aws-amplify": "0.2.15",

Auth question

Most helpful comment

Any news about this ?

All 3 comments

@DougWoodCDS Amplify currently will always refresh your session if it is expired:
https://github.com/aws/aws-amplify/blob/master/packages/aws-amplify/src/Auth/Auth.ts#L1346

We do have an issue tracking a feature to allow more flexibility around this e.g. don't auto refresh and subscribe to when refresh is going to occur. If this is what you are looking for we are tracking that here:
https://github.com/aws/aws-amplify/blob/master/packages/aws-amplify/src/Auth/Auth.ts#L1346

Closing the issue. Feel free to reopen if you have any question about that.

Any news about this ?

Was this page helpful?
0 / 5 - 0 ratings