amplify-js icon indicating copy to clipboard operation
amplify-js copied to clipboard

Hub does not currently emit an event when a refresh token expires or access token expires

Open mrSingh007 opened this issue 1 year ago • 7 comments

Before opening, please confirm:

JavaScript Framework

Angular

Amplify APIs

Authentication

Amplify Version

v6

Amplify Categories

auth

Backend

None

Environment information

# Put output below this line
OS: MacOS 13.5.2
CPU: (8) arm64 Apple M1 Pro
Memory: 51.52 MB / 16.00 GB

Node: 16.20.0
npm: 8.19.4

@aws-amplify/auth: ^6.0.10
@aws-amplify/auth: ^6.0.10
aws-amplify: ^6.0.10

Describe the bug

When access or refresh token is expired, no any event is sent to channel 'auth'. Page need to refresh manually to get new access token.

Expected behavior

When ever refresh token or access token expired, Hub should receive an event for 'auth' channel.

Reproduction steps

install the latest versions as mentioned above. Listen to events as following:

Hub.listen('auth', (msg:any) => { console.log('Event : ', msg) });

Used config:

Amplify.configure({
  Auth:{
    Cognito:{
       userPoolId:'<id>',
       userPoolClientId: '<id>',
       loginWith: {
           oauth: {
            domain:'<domain>'
            redirectSignIn: ['<url>'],
            redirectSignOut: ['<url>'],
            scopes: ['openid'],
            responseType: 'token'
           }
        }
      } 
   }
})

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

mrSingh007 avatar Jan 08 '24 19:01 mrSingh007

Seems there is no counter or task running that checks the expiry time of token and then dispatch the event.

mrSingh007 avatar Jan 08 '24 19:01 mrSingh007

hello @mrSingh007 . Thank you for bringing this up. We currently have a fix for this issue which needs to be released.

israx avatar Jan 08 '24 20:01 israx

Hello @mrSingh007 . The latest release included the fix, you should be able to get the hub event when the refresh_token is expired

israx avatar Jan 12 '24 15:01 israx

I have tested now in 5.3.15 and in version 6.0.12 of 'aws-amplify' and the issue is still there. No any event was dispatched, when token is expired.

mrSingh007 avatar Jan 15 '24 14:01 mrSingh007

@mrSingh007 you want an specific event when access or id token are expired? What is the use case?

Thanks!

elorzafe avatar Jan 30 '24 17:01 elorzafe

@mrSingh007 you should be able to see signOut event when the refresh_token is expired. The library emits this event when there is an API call that tries to pull tokens (e.g. fetchAuthSession API). The library cannot detect if the refresh_token is expired without doing an operation with Cognito service.

elorzafe avatar Feb 12 '24 20:02 elorzafe

@mrSingh007, did you get a chance to see @elorzafe's comment above? We'd like to know if there's additional context/use cases around this feature that we could work on. Would having just the expiration of the access token emit an event be enough here?

cwomack avatar Apr 09 '24 20:04 cwomack

Hey, @mrSingh007 👋. It looks like you may have had a similar question/issue resolved in #12832. Since we haven't heard back from you on this issue, we'll close this out for now. Feel free to reply back if there's still a question or blocker here, thanks!

cwomack avatar Jun 04 '24 20:06 cwomack