question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Potential bug: Calling signOut() before currentAuthenticatedUser() does not log the user out on react-native app restart

See original GitHub issue

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

# Put output below this line

  System:
    OS: macOS 11.4
    CPU: (8) arm64 Apple M1
    Memory: 95.45 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.16.0/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v14.16.0/bin/npm
  Browsers:
    Chrome: 91.0.4472.77
    Firefox: 88.0.1
    Safari: 14.1.1
  npmPackages:
    @aws-amplify/api: 4.0.1 => 4.0.1 
    @aws-amplify/auth: 4.0.1 => 4.0.1 
    @aws-amplify/core: 4.0.1 => 4.0.1 (4.0.3)
    @babel/core: ^7.8.4 => 7.12.16 (7.14.3)
    @babel/runtime: ^7.8.4 => 7.12.13 (7.14.0)
    @fortawesome/fontawesome-svg-core: ^1.2.35 => 1.2.35 
    @fortawesome/free-regular-svg-icons: ^5.15.3 => 5.15.3 
    @fortawesome/free-solid-svg-icons: ^5.15.3 => 5.15.3 
    @fortawesome/react-native-fontawesome: ^0.2.6 => 0.2.6 
    @onfido/react-native-sdk: ^1.3.4 => 1.3.4 
    @react-native-async-storage/async-storage: ^1.14.1 => 1.14.1 
    @react-native-community/datetimepicker: ^3.4.2 => 3.4.2 
    @react-native-community/eslint-config: ^1.1.0 => 1.1.0 
    @react-native-community/netinfo: ^5.9.10 => 5.9.10 
    @react-native-community/progress-bar-android: ^1.0.4 => 1.0.4 
    @react-native-community/progress-view: ^1.2.4 => 1.2.4 
    @sentry/react-native: ^2.3.0 => 2.4.0 
    @types/amplitude-js: ^7.0.1 => 7.0.1 
    @types/jest: ^25.2.3 => 25.2.3 
    @types/react-native: ^0.63.2 => 0.63.49 (0.64.2)
    @types/react-native-vector-icons: ^6.4.6 => 6.4.6 
    @types/react-test-renderer: ^16.9.2 => 16.9.5 
    @typescript-eslint/eslint-plugin: ^4.15.0 => 4.15.0 (2.34.0)
    HelloWorld:  0.0.1 
    PDFExample:  0.0.1 
    amazon-cognito-identity-js: ^4.5.11 => 4.5.11 (5.0.2)
    amplitude-js: ^7.4.2 => 7.4.2 
    babel-jest: ^25.1.0 => 25.5.1 
    date-fns: ^2.21.3 => 2.21.3 
    docs:  0.0.0 
    eslint: ^7.20.0 => 7.20.0 
    eslint-config-airbnb-typescript: ^12.3.1 => 12.3.1 
    eslint-config-prettier: ^7.2.0 => 7.2.0 (6.15.0)
    eslint-plugin-import: ^2.22.1 => 2.22.1 
    eslint-plugin-jsx-a11y: ^6.4.1 => 6.4.1 
    eslint-plugin-react: ^7.22.0 => 7.22.0 (7.19.0)
    example:  0.1.0 
    fbjs: ^3.0.0 => 3.0.0 
    hermes-inspector-msggen:  1.0.0 
    jest: ^25.1.0 => 25.5.4 
    memo-parser:  0.2.1 
    metro-react-native-babel-preset: ^0.59.0 => 0.59.0 (0.64.0)
    prettier: ^2.2.1 => 2.2.1 
    react: 17.0.1 => 17.0.1 
    react-native: 0.64.1 => 0.64.1 
    react-native-biometrics: ^2.1.4 => 2.1.4 
    react-native-chart-kit: ^6.11.0 => 6.11.0 
    react-native-device-info: ^8.0.1 => 8.0.1 
    react-native-navigation: 7.15.0 => 7.15.0 
    react-native-navigation-bar-color: ^2.0.1 => 2.0.1 
    react-native-pdf: ^6.3.0 => 6.3.0 
    react-native-smooth-pincode-input: ^1.0.9 => 1.0.9 
    react-native-svg: ^12.1.0 => 12.1.0 
    react-native-toast-message: ^1.4.9 => 1.4.9 
    react-native-vector-icons: ^8.1.0 => 8.1.0 
    react-redux: ^7.2.4 => 7.2.4 
    react-test-renderer: 16.13.1 => 16.13.1 
    redux: ^4.1.0 => 4.1.0 
    redux-persist: ^6.0.0 => 6.0.0 
    redux-persist/integration/react:  undefined ()
    rn-fetch-blob: ^0.12.0 => 0.12.0 
    typescript: ^3.8.3 => 3.9.9 
  npmGlobalPackages:
    npm: 6.14.11
    yarn: 1.22.10

Describe the bug

Calling Auth.SignOut() before any call to Auth.currentAuthenticatedUser() does not log the user out on react-native application restart. I don’t think the react-native part is relevant but am including it just in case.

Expected behavior

Calling Auth.SignOut() will log the user out if Auth.currentAuthenticatedUser() would have returned a non-null value.

Reproduction steps

  1. Write react-native app that uses @aws-amplify/auth
  2. Log in using Auth.signIn()
  3. Restart App
  4. Call Auth.signOut() -> This will not log the user out.
  5. Call Auth.currentAuthenticatedUser() then Auth.signOut() -> This will log the user out.

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bertrand-caroncommented, Jun 6, 2021

Hey @chrisbonifacio, thanks for looking into this.

I’m calling Auth.signOut() before any calls to Auth. currentAuthenticatedUser(). It just seemed very counter-intuitive to me that Auth. currentAuthenticatedUser() would succeed, but Auth.signOut() did not (unless I had called Auth. currentAuthenticatedUser() before).

Does that make sense?

Maybe this does not warrant any code change, but at least documentation update to Auth.signOut() to make it explicit? I spent much longer than I’d like to admit understanding what was happening.

0reactions
pepsocommented, Sep 14, 2021

I think I experienced the same bug on React web-app right now with: “aws-amplify-react”: “^5.0.13” / “@aws-amplify/ui-react”: “^1.2.14”,

My scenario:

  1. Two tabs open for the same app.
  2. On another I used hostedUI signout button to signout, which then cleared the local storage session variables and took me to sinin page.
  3. In quick succession, on the other tab, I continued to use the session and call my backend as authenticated user like session was still going on remotely.

So does singOut() actually not singout the user? It just removes the local storage/session information of the authenticated session only?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Amplify Hub.listen immediately calls signOut after signIn when ...
I'm having an issue implementing SSO with AWS Amplify into my React Native app. I have SSO working fine, however, when trying to...
Read more >
Authentication - Social sign-in (OAuth) - React Native
OAuth 2.0 is the common Authorization framework used by web and mobile applications for getting access to user information ("scopes") in a limited...
Read more >
Tutorial: Create a React single-page app that uses auth code ...
In this tutorial, you create a React SPA that can sign in users and use ... and sign-out; Add code to call Microsoft...
Read more >
AWS Amplify Authentication in React Native (Full tutorial)
Learn how to integrate a custom authentication UI in React Native with AWS Amplify Authentication. The tutorial will walk you through the ...
Read more >
The Complete React Native Guide to User Authentication with ...
An in depth guide for adding authentication to your next mobile app using React Native and AWS Amplify. Tagged with aws, reactnative, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found