aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

After a token refresh, signInDetails is undefined #13063

Closed gk-bbai closed 6 months ago

gk-bbai commented 7 months ago

Before opening, please confirm:

JavaScript Framework

Not applicable

Amplify APIs

Authentication

Amplify Version

v6

Amplify Categories

auth

Backend

None

Environment information

``` Browsers: Firefox: 123.0 npmPackages: @angular-devkit/build-angular: ~17.0.0 => 17.0.10 @angular-devkit/core: ~17.0.0 => 17.0.10 @angular-devkit/schematics: ~17.0.0 => 17.0.10 @angular-devkit/schematics/tasks: undefined () @angular-devkit/schematics/testing: undefined () @angular-devkit/schematics/tools: undefined () @angular-eslint/eslint-plugin: ~17.0.0 => 17.0.1 @angular-eslint/eslint-plugin-template: ~17.0.0 => 17.0.1 @angular-eslint/template-parser: ~17.0.0 => 17.0.1 @angular/animations: ~17.0.0 => 17.0.9 @angular/cli: ~17.0.0 => 17.0.10 @angular/common: ~17.0.0 => 17.0.9 @angular/compiler: ~17.0.0 => 17.0.9 @angular/compiler-cli: ~17.0.0 => 17.0.9 @angular/core: ~17.0.0 => 17.0.9 @angular/forms: ~17.0.0 => 17.0.9 @angular/language-service: ~17.0.0 => 17.0.9 @angular/platform-browser: ~17.0.0 => 17.0.9 @angular/platform-browser-dynamic: ~17.0.0 => 17.0.9 @angular/router: ~17.0.0 => 17.0.9 @cypress/angular: 0.0.0-development @cypress/mount-utils: 0.0.0-development @cypress/react: 0.0.0-development @cypress/react18: 0.0.0-development @cypress/svelte: 0.0.0-development @cypress/vue: 0.0.0-development @cypress/vue2: 0.0.0-development @fontsource/nunito: ^5.0.16 => 5.0.16 @fontsource/roboto: ^5.0.8 => 5.0.8 @nx/angular: 17.2.8 => 17.2.8 @nx/cypress: 17.2.8 => 17.2.8 @nx/eslint: 17.2.8 => 17.2.8 @nx/eslint-plugin: 17.2.8 => 17.2.8 @nx/jest: 17.2.8 => 17.2.8 @nx/js: 17.2.8 => 17.2.8 @nx/storybook: ^17.2.8 => 17.2.8 @nx/web: 17.2.8 => 17.2.8 @nx/workspace: 17.2.8 => 17.2.8 @schematics/angular: ~17.0.0 => 17.0.10 @storybook/addon-essentials: ^7.5.3 => 7.6.10 @storybook/addon-interactions: ^7.5.3 => 7.6.10 @storybook/angular: ^7.5.3 => 7.6.10 @storybook/core-server: ^7.5.3 => 7.6.10 @storybook/jest: ^0.2.3 => 0.2.3 @storybook/test-runner: ^0.13.0 => 0.13.0 @storybook/testing-library: ^0.2.2 => 0.2.2 @swc-node/register: ~1.6.7 => 1.6.8 @swc/core: ~1.3.85 => 1.3.105 @types/jest: ^29.4.0 => 29.5.11 (28.1.3) @types/node: 18.16.9 => 18.16.9 @typescript-eslint/eslint-plugin: ^6.9.1 => 6.19.1 @typescript-eslint/parser: ^6.9.1 => 6.19.1 aws-amplify: ^6.0.18 => 6.0.18 aws-amplify/adapter-core: undefined () aws-amplify/analytics: undefined () aws-amplify/analytics/kinesis: undefined () aws-amplify/analytics/kinesis-firehose: undefined () aws-amplify/analytics/personalize: undefined () aws-amplify/analytics/pinpoint: undefined () aws-amplify/api: undefined () aws-amplify/api/server: undefined () aws-amplify/auth: undefined () aws-amplify/auth/cognito: undefined () aws-amplify/auth/cognito/server: undefined () aws-amplify/auth/enable-oauth-listener: undefined () aws-amplify/auth/server: undefined () aws-amplify/datastore: undefined () aws-amplify/in-app-messaging: undefined () aws-amplify/in-app-messaging/pinpoint: undefined () aws-amplify/push-notifications: undefined () aws-amplify/push-notifications/pinpoint: undefined () aws-amplify/storage: undefined () aws-amplify/storage/s3: undefined () aws-amplify/storage/s3/server: undefined () aws-amplify/storage/server: undefined () aws-amplify/utils: undefined () cypress: ^13.0.0 => 13.6.3 eslint: ~8.48.0 => 8.48.0 eslint-config-prettier: ^9.0.0 => 9.1.0 eslint-plugin-cypress: ^2.13.4 => 2.15.1 jest: ^29.4.1 => 29.7.0 (28.1.3) jest-environment-jsdom: ^29.4.1 => 29.7.0 jest-preset-angular: ~13.1.4 => 13.1.6 jsonc-eslint-parser: ^2.1.0 => 2.4.0 nx: 17.2.8 => 17.2.8 prettier: ^2.6.2 => 2.8.8 primeicons: ^6.0.1 => 6.0.1 primeng: ^17.3.3 => 17.3.3 react: ^18.2.0 => 18.2.0 react-dom: ^18.2.0 => 18.2.0 rxjs: ~7.8.0 => 7.8.1 (6.6.7) rxjs/ajax: undefined () rxjs/fetch: undefined () rxjs/internal-compatibility: undefined () rxjs/operators: undefined () rxjs/testing: undefined () rxjs/webSocket: undefined () ts-jest: ^29.1.0 => 29.1.2 ts-node: 10.9.1 => 10.9.1 tslib: ^2.3.0 => 2.6.2 (1.14.1) typescript: ~5.2.2 => 5.2.2 zone.js: ~0.14.0 => 0.14.3 npmGlobalPackages: corepack: 0.23.0 npm: 10.2.4 ```

Describe the bug

The value returned by getCurrentUser() (and within the token property of the value returned by fetchAuthSession()) does not include signInDetails after a token refresh is triggered.

Expected behavior

If the user is properly authenticated , either signInDetails should always be present or another way to get the loginId needs to be added.

Reproduction steps

In AWS cognito:

  1. Setup a new app client for a user pool
    1. Set the ID token expiration to 5 minutes

In a JavaScript client application:

  1. Call signIn(...) as normal
  2. Call getCurrentUser()
    • Observe that the return value includes a signInDetails property
  3. Wait 5 minutes
  4. Call getCurrentUser()
    • Observe that the return value no longer includes a signInDetails property

Code Snippet

// Setup debug logging
Hub.listen('auth', async data => {
    console.log('New auth event:', data)

    switch (data.payload.event) {
        case 'signedIn': {
            // Check signInDetails for current user
            const currentUser = await getCurrentUser()
            console.debug('currentUser after sign in:', currentUser.signInDetails) // { loginId: "...", authFlowType: "..." }
            break
        }
        case 'tokenRefresh': {
            const currentUser = await getCurrentUser()
            console.debug('currentUser after token refresh:', currentUser.signInDetails) // undefined
            break
        }
    }
})

// Sign in
const signedIn = await signIn({ username, password })
console.log('signIn():', signedIn)

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

cwomack commented 7 months ago

Hello, @gk-bbai 👋. Appreciate you opening this issue with such great context and details! We're currently investigating this and will mark it as a bug for now.

Mikimann commented 7 months ago

On a somehow related note, shouldn`t the user object that is returned have multiple properties on it? It currently only has username, userId and signInDetails. I am trying to get the jwt token, which is nowhere to be found.

NairiAreg commented 7 months ago

On a somehow related note, shouldn`t the user object that is returned have multiple properties on it? It currently only has username, userId and signInDetails. I am trying to get the jwt token, which is nowhere to be found.

fetchAuthSession() has accessToken and idToken

NairiAreg commented 7 months ago

I have the same bug, it's very critical, users just drops from their login session The worst part is that they can't log back in, because it tells UserAlreadyAuthenticatedException: There is already a signed in user

israx commented 7 months ago

Hello @gk-bbai . We released a fix on the latest version of the library. Can you try it out ? Please delete node_modules and package.lock.json file before upgrading the amplify dependency.

josefaidt commented 6 months ago

closing due to inactivity and merge & release of #13153