Skip to content

Calling getCurrentSession promise hangs after signing out in a different tab #14344

Closed
@hututudor

Description

@hututudor

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Authentication

Amplify Version

v6

Amplify Categories

auth

Backend

Other

Environment information

  System:
    OS: macOS 15.3
    CPU: (14) arm64 Apple M4 Max
    Memory: 5.32 GB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.1 - ~/.nvm/versions/node/v20.18.1/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v20.18.1/bin/npm
  Browsers:
    Chrome: 135.0.7049.85
    Safari: 18.3
  npmPackages:
    @apollo/client: ^3.8.4 => 3.13.6 
    @apollo/client/cache:  undefined ()
    @apollo/client/core:  undefined ()
    @apollo/client/dev:  undefined ()
    @apollo/client/errors:  undefined ()
    @apollo/client/link/batch:  undefined ()
    @apollo/client/link/batch-http:  undefined ()
    @apollo/client/link/context:  undefined ()
    @apollo/client/link/core:  undefined ()
    @apollo/client/link/error:  undefined ()
    @apollo/client/link/http:  undefined ()
    @apollo/client/link/persisted-queries:  undefined ()
    @apollo/client/link/remove-typename:  undefined ()
    @apollo/client/link/retry:  undefined ()
    @apollo/client/link/schema:  undefined ()
    @apollo/client/link/subscriptions:  undefined ()
    @apollo/client/link/utils:  undefined ()
    @apollo/client/link/ws:  undefined ()
    @apollo/client/masking:  undefined ()
    @apollo/client/react:  undefined ()
    @apollo/client/react/components:  undefined ()
    @apollo/client/react/context:  undefined ()
    @apollo/client/react/hoc:  undefined ()
    @apollo/client/react/hooks:  undefined ()
    @apollo/client/react/internal:  undefined ()
    @apollo/client/react/parser:  undefined ()
    @apollo/client/react/ssr:  undefined ()
    @apollo/client/testing:  undefined ()
    @apollo/client/testing/core:  undefined ()
    @apollo/client/testing/experimental:  undefined ()
    @apollo/client/utilities:  undefined ()
    @apollo/client/utilities/globals:  undefined ()
    @apollo/client/utilities/subscriptions/relay:  undefined ()
    @apollo/client/utilities/subscriptions/urql:  undefined ()
    @babel/eslint-plugin: ^7.0.0 => 7.27.0 
    @babel/plugin-proposal-private-property-in-object: ^7.21.11 => 7.21.11 (7.21.0-placeholder-for-preset-env.2)
    @datadog/browser-logs: ^4.49.0 => 4.50.1 
    @datadog/browser-rum: ^4.49.0 => 4.50.1 
    @datadog/datadog-ci: ^2.8.0 => 2.48.0 
    @etvas/etvaskit: 2.0.69 => 2.0.69 
    @etvas/i18n: ^2.0.1 => 2.0.2 
    @trivago/prettier-plugin-sort-imports: ^4.1.1 => 4.3.0 
    @welldone-software/why-did-you-render: ^3.5.0 => 3.6.0 
    aws-amplify: ^6.14.0 => 6.14.1 
    aws-amplify/adapter-core:  undefined ()
    aws-amplify/adapter-core/internals:  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/internals:  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/data:  undefined ()
    aws-amplify/data/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 ()
    aws-appsync-auth-link: ^3.0.7 => 3.0.7 
    aws-appsync-subscription-link: ^3.1.2 => 3.1.3 
    aws-sdk: 2.1357.0 => 2.1357.0 
    env-cmd: ^10.0.1 => 10.1.0 
    etvas-internals: github:etvascom/etvas-internals => 2.0.2 
    formik: ^2.4.3 => 2.4.6 
    graphql-tag: ^2.10.1 => 2.12.6 
    husky: ^4.2.0 => 4.3.8 
    js-cookie: ^3.0.5 => 3.0.5 
    lint-staged: ^10.0.2 => 10.5.4 
    moment: ^2.29.4 => 2.30.1 
    postcss-flexbugs-fixes: ^5.0.2 => 5.0.2 
    postcss-normalize: ^10.0.1 => 10.0.1 
    postcss-preset-env: ^8.3.1 => 8.5.1 (7.8.3)
    prettier-eslint: ^12.0.0 => 12.0.0 (9.0.2)
    prettier-eslint-cli: ^5.0.0 => 5.0.1 
    query-string: ^6.10.1 => 6.14.1 
    react: ^18.2.0 => 18.3.1 
    react-app-rewired: ^2.1.8 => 2.2.1 
    react-dom: ^18.2.0 => 18.3.1 
    react-error-overlay: ^6.0.9 => 6.1.0 
    react-remove-props-loader: ^1.2.4 => 1.2.12 
    react-router-dom: ^5.3.0 => 5.3.4 
    react-scripts: ^5.0.1 => 5.0.1 
    styled-components: ^6.1.1 => 6.1.17 
    styled-components/native:  undefined ()
    stylelint: ^13.0.0 => 13.13.1 
    stylelint-config-recommended: ^3.0.0 => 3.0.0 
    stylelint-config-styled-components: ^0.1.1 => 0.1.1 
    stylelint-processor-styled-components: ^1.9.0 => 1.10.0 
  npmGlobalPackages:
    @etvas/etvas-cli: 2.1.11
    corepack: 0.29.4
    kill-port: 2.0.1
    npm: 10.8.2
    serve: 14.2.4
    typescript: 5.7.3

Describe the bug

When calling the signOut function from a second tab of our application, we see that upon returning to the first tab(where the user was logged in) and calling the fetchAuthSession function in an window.onFocus handler to observe the status of the user, the promise is never resolving (no response is returned and no error is thrown either).

Expected behavior

We expect the promise to throw an error, since the user is not logged in the app anymore.

Reproduction steps

  1. Have a logged in user in your app
  2. Have a window.onfocus event registered to trigger the fetchAuthSession() call when the user focuses on the app. Additionally, you should add a log before and after the call to see if the promise hanging.
  3. Open a secondary tab of the same app (we tested both on localhost and deployed version and the observed behavior is the same)
  4. Call signOut() from an action in the secondary tab
  5. Return to the first tab to find out the promise was called, but never will resolve.

Code Snippet

import { fetchAuthSession } from 'aws-amplify/auth'

...

window.onfocus = async ev => {
 try {
   console.log('will try to get current session')
   const session = await fetchAuthSession()
   console.log('got current session', session)
 } catch (error) {
   await history.push('/signIn')
 }
}

Log output

Image

aws-exports.js

No response

Manual configuration

export const awsConfig = {
  Auth: {
    Cognito: {
      authenticationFlowType: 'USER_PASSWORD_AUTH',
      identityPoolId: process.env.REACT_APP_IDENTITY_POOL_ID,
      userPoolId: process.env.REACT_APP_USER_POOL_ID,
      userPoolClientId: process.env.REACT_APP_WEB_CLIENT_ID,
      loginWith: {
        oauth: {
          domain: process.env.REACT_APP_OAUTH_DOMAIN,
          scopes: [
            'phone',
            'email',
            'profile',
            'openid',
            'aws.cognito.signin.user.admin'
          ],
          responseType: 'code',
          redirectSignIn: [getCallback('/auth')],
          redirectSignOut: [getCallback('/auth')]
        }
      }
    }
  },
  API: {
    GraphQL: {
      region: process.env.REACT_APP_AWS_GRAPHQL_REGION,
      endpoint: process.env.REACT_APP_AWS_GRAPHQL_ENDPOINT,
      defaultAuthMode: process.env.REACT_APP_AWS_GRAPHQL_AUTHENTICATION_TYPE
    }
  }
}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    AuthRelated to Auth components/categoryquestionGeneral question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions