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.44k stars 2.13k forks source link

Users signed out if internet connection lost #14033

Closed ab-bee closed 1 hour ago

ab-bee commented 22 hours ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication

Amplify Version

v6

Amplify Categories

auth

Backend

None

Environment information

``` # Put output below this line System: OS: macOS 15.0.1 CPU: (8) arm64 Apple M2 Memory: 42.89 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node Yarn: 1.22.22 - ~/.yarn/bin/yarn npm: 10.8.3 - ~/.nvm/versions/node/v18.18.0/bin/npm pnpm: 9.14.2 - ~/.nvm/versions/node/v18.18.0/bin/pnpm Browsers: Safari: 18.0.1 npmPackages: @aws-amplify/react-native: ^1.1.6 => 1.1.6 @babel/core: ^7.22.11 => 7.24.7 @babel/preset-env: ^7.22.11 => 7.24.7 @babel/runtime: ^7.22.11 => 7.24.7 @react-native-async-storage/async-storage: ^1.23.1 => 1.23.1 @react-native-community/datetimepicker: ^8.0.0 => 8.0.1 @react-native-community/netinfo: ^11.0.0 => 11.3.2 @react-native-firebase/analytics: ^19.1.1 => 19.3.0 @react-native-firebase/app: ^19.1.1 => 19.3.0 @react-native-firebase/dynamic-links: ^19.1.1 => 19.3.0 @react-native-picker/picker: ^2.4.9 => 2.7.7 @react-native/babel-preset: 0.73.21 => 0.73.21 @react-native/eslint-config: 0.73.2 => 0.73.2 @react-native/metro-config: 0.73.5 => 0.73.5 @react-native/typescript-config: 0.73.1 => 0.73.1 @react-navigation/core: ^6.2.2 => 6.2.2 @react-navigation/drawer: ^6.6.2 => 6.6.15 @react-navigation/native: ^6.0.11 => 6.0.11 @react-navigation/stack: ^6.2.2 => 6.2.2 @redux-devtools/extension: ^3.0.0 => 3.3.0 @redux-saga/testing-utils: ^1.1.3 => 1.1.5 @reduxjs/toolkit: ^1.9.5 => 1.9.7 @reduxjs/toolkit-query: 1.0.0 @reduxjs/toolkit-query-react: 1.0.0 @sentry/integrations: ^7.119.0 => 7.119.0 @sentry/react-native: ^5.33.1 => 5.33.1 @testing-library/jest-native: ^5.4.3 => 5.4.3 @testing-library/react-native: ^12.3.2 => 12.5.1 @types/base-64: ^1.0.0 => 1.0.2 @types/jest: ^29.2.1 => 29.5.12 @types/react: ^18.0.24 => 18.3.5 @types/react-dom: ^18.0.0 => 18.3.0 @types/react-native-vector-icons: ^6.4.10 => 6.4.18 @types/react-redux: 7.1.33 => 7.1.33 @types/react-test-renderer: ^18.0.0 => 18.0.0 @types/uuid: ^10.0.0 => 10.0.0 (9.0.8) @types/yup: ^0.29.14 => 0.29.14 @typescript-eslint/eslint-plugin: ^7.18.0 => 7.18.0 (5.62.0) @typescript-eslint/parser: ^7.18.0 => 7.18.0 (5.62.0) @welldone-software/why-did-you-render: ^7.0.1 => 7.0.1 HelloWorld: 0.0.1 LocationEnable: 0.0.1 SimpleEnable: 0.0.1 aws-amplify: ^6.9.0 => 6.9.0 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/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 () axios: ^1.5.0 => 1.5.0 babel-jest: ^29.6.3 => 29.7.0 base-64: ^1.0.0 => 1.0.0 date-fns: 2.30.0 => 2.30.0 date-fns-tz: 1.3.8 => 1.3.8 eslint: ^8.57.0 => 8.57.0 eslint-config-airbnb: ^19.0.4 => 19.0.4 eslint-config-airbnb-typescript: ^18.0.0 => 18.0.0 eslint-config-prettier: 8.10.0 => 8.10.0 eslint-import-resolver-typescript: ^2.7.1 => 2.7.1 eslint-plugin-eslint-comments: ^3.2.0 => 3.2.0 eslint-plugin-import: ^2.29.1 => 2.29.1 eslint-plugin-jest: ^28.8.2 => 28.8.2 (26.9.0) eslint-plugin-jsx-a11y: ^6.9.0 => 6.9.0 eslint-plugin-react: ^7.35.0 => 7.35.0 eslint-plugin-react-hooks: ^4.6.2 => 4.6.2 eslint-plugin-react-native: ^4.1.0 => 4.1.0 formik: ^2.4.6 => 2.4.6 jest: ^29.7.0 => 29.7.0 jest-environment-jsdom: ^29.2.1 => 29.7.0 jest-mock-extended: ^3.0.1 => 3.0.7 jest-transform-stub: ^2.0.0 => 2.0.0 mockdate: ^3.0.5 => 3.0.5 openapi-typescript: ^6.0.0-pre.0 => 6.7.6 patch-package: ^8.0.0 => 8.0.0 postinstall-postinstall: ^2.1.0 => 2.1.0 prettier: 2.8.8 => 2.8.8 react: 18.2.0 => 18.2.0 react-devtools: ^4.25.0 => 4.25.0 react-dom: 18.2.0 => 18.2.0 react-native: ^0.73.6 => 0.73.6 react-native-android-location-enabler: ^1.2.2 => 1.2.2 react-native-ble-plx: ^3.1.2 => 3.1.2 react-native-camera: ^4.2.1 => 4.2.1 react-native-code-push: ^8.2.1 => 8.2.2 react-native-config: ^1.4.5 => 1.4.5 react-native-devsettings: ^1.0.5 => 1.0.5 react-native-gesture-handler: ^2.16.0 => 2.16.2 react-native-get-random-values: 1.8.0 => 1.8.0 react-native-inappbrowser-reborn: ^3.7.0 => 3.7.0 react-native-keyboard-aware-scroll-view: ^0.9.5 => 0.9.5 react-native-localize: ^2.2.2 => 2.2.6 react-native-modal-datetime-picker: ^18.0.0 => 18.0.0 react-native-onesignal: ^5.0.4 => 5.2.2 react-native-pager-view: ^6.1.4 => 6.1.4 react-native-paper: ^5.12.3 => 5.12.3 react-native-permissions: ^4.1.5 => 4.1.5 react-native-qrcode-scanner: ^1.5.5 => 1.5.5 react-native-reanimated: ^3.8.1 => 3.8.1 react-native-safe-area-context: ^4.3.1 => 4.7.1 react-native-screens: ^3.29.0 => 3.29.0 react-native-svg: ^13.4.0 => 13.13.0 react-native-svg-transformer: ^1.3.0 => 1.3.0 react-native-swipe-list-view: ^3.2.9 => 3.2.9 react-native-tab-view: ^3.5.2 => 3.5.2 react-native-url-polyfill: ^2.0.0 => 2.0.0 react-native-vector-icons: ^10.0.0 => 10.0.0 react-redux: ^8.1.2 => 8.1.3 react-test-renderer: 18.2.0 => 18.2.0 react-uid: ^2.3.2 => 2.3.3 redux: ^4.0.1 => 4.2.1 redux-saga: ^1.1.1 => 1.1.3 redux-saga/effects: undefined () semver: ^7.6.3 => 7.6.3 (6.3.1, 7.5.4, 7.3.7, 5.7.1, 7.6.2) typescript: 5.0.4 => 5.0.4 uuid: ^10.0.0 => 10.0.0 (9.0.1, 7.0.3) victory-native: 36.9.2 => 36.9.2 yup: ^0.30.0 => 0.30.0 npmGlobalPackages: corepack: 0.19.0 npm: 10.8.3 ```

Describe the bug

Users are signed out before their refresh token expires if they lose internet connection.

There are no tokens in local storage when they're signed out.

Using the latest AWS Amplify version (v6.9.0).

Expected behavior

Users remain signed in until their refresh token expires.

Reproduction steps

  1. Set access and ID token expiration to 5 minutes
  2. Set refresh token expiration to 60 minutes
  3. Sign in, disable the internet connection, and wait 5-10 minutes
  4. You should be signed out and see no tokens in local storage, if using react-native-async-storage

Log output

``` // Put your logs below this line # Before user signed out: { "@MemoryStorage:CognitoIdentityServiceProvider.61bvred0ajga966hutm2ahcls9.LastAuthUser": { "content": "" }, "@MemoryStorage:CognitoIdentityServiceProvider.61bvred0ajga966hutm2ahcls9.": { "content": "" }, "@MemoryStorage:CognitoIdentityServiceProvider.61bvred0ajga966hutm2ahcls9..clockDrift": { "content": "37" }, "@MemoryStorage:CognitoIdentityServiceProvider.61bvred0ajga966hutm2ahcls9..idToken": { "content": "" }, "@MemoryStorage:CognitoIdentityServiceProvider.61bvred0ajga966hutm2ahcls9..refreshToken": { "content": "" }, "@MemoryStorage:CognitoIdentityServiceProvider.61bvred0ajga966hutm2ahcls9..signInDetails": { "content": "{\"loginId\":\"\",\"authFlowType\":\"USER_SRP_AUTH\"}" }, "@RNDS/isDebuggingRemotely": { "content": "true" } } # After user signed out: { "@RNDS/isDebuggingRemotely": { "content": "true" } } ```

Manual configuration

{
    Auth: {
      Cognito: {
        userPoolId: <redacted>,
        userPoolClientId: <redacted>,
      },
    },
    Geo: { LocationService: { region: 'ap-southeast-2' } },
}

Mobile Operating System

Android

HuiSF commented 5 hours ago

Hi @ab-bee, thanks for reporting this issue we will start investigation.

Also could you clarify:

see no tokens in local storage

by local storage, you mean the underlying AsyncStorage of your react-native app?

HuiSF commented 4 hours ago

Hi @ab-bee I couldn't reproduce this error in a react-native app that's running on Android. I also verified that when no network connection, the underlying refresh tokens service calls failed due to NetworkError, but the expired tokens remain in the AsyncStorage along with the effective refresh token. And when the device regain network, refresh token worked correctly.

We recently fixed (v6.7.0) a bug that disturbed the above flows and causing the tokens to be cleared. If you upgraded aws-amplify from an older version, could you try to clean all build cache and try again?

ab-bee commented 1 hour ago

Hi @ab-bee, thanks for reporting this issue we will start investigation.

Also could you clarify:

see no tokens in local storage

by local storage, you mean the underlying AsyncStorage of your react-native app?

Thank you! Yes, that's right.

HuiSF commented 1 hour ago

Thank you for confirming @ab-bee. Were you able to verify the suggestion I gave above?

ab-bee commented 1 hour ago

Thank you for confirming @ab-bee. Were you able to verify the suggestion I gave above?

Hi again, I have cleared out the node_modules and build cache and can't reproduce this again. Will close the issue, thank you.