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

Local storage is missing an ID Token, Please authenticate error when using SignIn with custom authentication on react-native #9215

Closed tl1993 closed 1 year ago

tl1993 commented 2 years ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

``` System: OS: macOS 11.5.2 CPU: (8) x64 Apple M1 Memory: 20.21 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.17.4 - /usr/local/bin/node npm: 6.14.9 - ~/committed/apollo-app/node_modules/.bin/npm Watchman: 2021.08.02.00 - /opt/homebrew/bin/watchman Browsers: Chrome: 95.0.4638.69 Safari: 14.1.2 npmPackages: @babel/core: 7.8.4 => 7.8.4 @babel/runtime: 7.8.4 => 7.8.4 (7.12.1) @fortawesome/free-brands-svg-icons: ^5.15.1 => 5.15.1 @fortawesome/pro-light-svg-icons: ^5.15.1 => 5.15.1 @fortawesome/pro-regular-svg-icons: ^5.15.1 => 5.15.1 @fortawesome/pro-solid-svg-icons: ^5.15.1 => 5.15.1 @react-native-async-storage/async-storage: ^1.15.11 => 1.15.11 @react-native-community/blur: ^3.6.0 => 3.6.0 @react-native-community/clipboard: ^1.5.1 => 1.5.1 @react-native-community/datetimepicker: ^3.0.4 => 3.0.4 @react-native-community/eslint-config: 1.1.0 => 1.1.0 @react-native-community/masked-view: 0.1.10 => 0.1.10 @react-native-community/netinfo: ^5.9.10 => 5.9.10 @react-native-community/picker: ^1.8.1 => 1.8.1 @react-native-community/progress-bar-android: ^1.0.4 => 1.0.4 @react-native-community/progress-view: ^1.3.1 => 1.3.1 @react-native-firebase/app: ^10.8.1 => 10.8.1 @react-native-firebase/messaging: ^10.8.1 => 10.8.1 @react-navigation/bottom-tabs: ^5.9.2 => 5.9.2 @react-navigation/drawer: ^5.9.3 => 5.9.3 @react-navigation/native: ^5.7.6 => 5.9.4 @react-navigation/stack: ^5.9.3 => 5.14.4 @reduxjs/toolkit: ^1.5.0 => 1.5.0 @types/jest: 25.2.3 => 25.2.3 @types/lodash: 4.14.162 => 4.14.162 @types/react-native: 0.63.2 => 0.63.2 @types/react-native-background-timer: ^2.0.0 => 2.0.0 @types/react-native-incall-manager: ^3.2.1 => 3.2.1 @types/react-native-share: ^3.3.0 => 3.3.0 @types/react-native-vector-icons: ^6.4.6 => 6.4.6 @types/react-redux: 7.1.9 => 7.1.9 @types/react-test-renderer: 16.9.2 => 16.9.2 @types/uuid: ^8.3.0 => 8.3.0 @types/yup: 0.29.8 => 0.29.8 @typescript-eslint/eslint-plugin: 2.27.0 => 2.27.0 @typescript-eslint/parser: 2.27.0 => 2.27.0 HelloWorld: 0.0.1 ReactNativeBlobUtilWin: 0.0.1 amazon-cognito-identity-js: ^5.2.3 => 5.2.3 aws-amplify: ^4.3.5 => 4.3.5 aws-amplify-react-native: ^4.3.3 => 4.3.3 axios: ^0.21.1 => 0.21.1 (0.21.4) babel-jest: 25.1.0 => 25.1.0 (25.5.1) babel-plugin-module-resolver: 4.0.0 => 4.0.0 benchmark-uuid: undefined () cross-env: 7.0.2 => 7.0.2 enum: ^3.0.4 => 3.0.4 eslint: 6.5.1 => 6.5.1 eslint-plugin-uilib: 1.0.27 formik: 2.1.7 => 2.1.7 hermes-inspector-msggen: 1.0.0 i18next: 19.8.2 => 19.8.2 install: ^0.13.0 => 0.13.0 jest: 25.1.0 => 25.1.0 lodash: 4.17.20 => 4.17.20 (3.10.1, 4.17.4) metro-react-native-babel-preset: 0.59.0 => 0.59.0 moment: 2.29.1 => 2.29.1 npm: ^6.14.9 => 6.14.9 npm-cli-docs: 0.1.0 plop: ^2.7.4 => 2.7.4 plop-example: undefined () prop-types: ^15.7.2 => 15.7.2 react: 16.13.1 => 16.13.1 react-animated: 0.1.0 react-i18next: 11.7.3 => 11.7.3 react-native: ^0.63.3 => 0.63.4 react-native-background-timer: ^1.3.0 => 1.3.0 react-native-blob-util: ^0.13.16 => 0.13.16 react-native-callkeep: git://github.com/jpudysz/react-native-callkeep => 3.0.13 react-native-config: 1.3.3 => 1.3.3 react-native-confirmation-code-field: ^6.5.0 => 6.5.0 react-native-device-info: ^7.2.1 => 7.2.1 react-native-dropdown-picker: ^3.8.3 => 3.8.3 react-native-exit-app: ^1.1.0 => 1.1.0 react-native-fontawesome-pro: ^2.1.0 => 2.1.0 react-native-gesture-handler: ^1.7.0 => 1.8.0 react-native-gifted-chat: ^0.16.3 => 0.16.3 react-native-htmlview: ^0.16.0 => 0.16.0 react-native-icon-badge: ^1.1.3 => 1.1.3 react-native-inappbrowser-reborn: ^3.5.1 => 3.5.1 react-native-incall-manager: ^3.3.0 => 3.3.0 react-native-incoming-call: ^2.0.3 => 2.0.3 react-native-keychain: ^6.2.0 => 6.2.0 react-native-launch-application: ^1.0.1 => 1.0.1 react-native-linear-gradient: ^2.5.6 => 2.5.6 react-native-outline-input: ^1.0.8 => 1.0.8 react-native-parsed-text: 0.0.22 => 0.0.22 react-native-pdf: ^6.3.0 => 6.4.0 react-native-permissions: ^3.0.5 => 3.0.5 react-native-reanimated: ^1.13.1 => 1.13.1 react-native-render-html: ^4.2.4 => 4.2.4 react-native-restart: 0.0.17 => 0.0.17 react-native-safari-view: ^2.1.0 => 2.1.0 react-native-safe-area-context: 3.1.8 => 3.1.8 react-native-screens: ^2.11.0 => 2.11.0 react-native-share: ^4.1.0 => 4.1.0 react-native-shared-element: ^0.7.0 => 0.7.0 react-native-svg: ^12.1.1 => 12.1.1 react-native-ui-lib: ^5.15.0 => 5.15.0 react-native-vector-icons: 7.1.0 => 7.1.0 react-native-voip-push-notification: ^3.3.0 => 3.3.0 react-native-webview: ^10.10.2 => 10.10.2 react-navigation-shared-element: ^5.0.0-alpha1 => 5.0.0-alpha1 react-redux: 7.2.1 => 7.2.1 react-test-renderer: 16.13.1 => 16.13.1 redux-thunk: 2.3.0 => 2.3.0 rn-fetch-blob: ^0.12.0 => 0.12.0 standard-version: ^9.0.0 => 9.0.0 typescript: 3.8.3 => 3.8.3 uilib-native: 3.0.4 uuid: ^3.4.0 => 3.4.0 (3.3.2, 8.3.2, 2.0.3, 3.1.0, 3.3.3) yup: 0.29.3 => 0.29.3 npmGlobalPackages: heroku: 7.59.1 moralis-admin-cli: 2.1.14 npm: 6.14.14 truffle: 5.4.18 ```

Describe the bug

Hi, we implemented custom auth authentication and tested it successfully using AWS Amplify 4.3.3 for ReactJS. When we are trying to use the same SignIn method on react native we are getting the next error: ExceptionsManager.js:179 [ERROR] 20:35.577 AuthClass - Failed to get the signed in user Error: Local storage is missing an ID Token, Please authenticate at CognitoUser.getSession (CognitoUser.js:1443) at AuthClass. (Auth.js:1150) at step (tslib.js:141) at Object.next (tslib.js:122) at tslib.js:115 at tryCallTwo (core.js:45) at doResolve (core.js:200) at new Promise (core.js:66) at __awaiter (tslib.js:111)

We even tried using our on custom storage class for the auth configuration but it did not help

Expected behavior

SignIn should return the CognitoUser object.

Reproduction steps

1.configure Custom Auth authentications

  1. Configure Amplify to use the user pool
  2. try to signIn with Auth.signIn({ username: , password: "" })

Code Snippet

export const getCognitoAuth = () => { const mandatorySignId = true; const POOL_ID = const REGION = envConfig.AWS_REGION const CLIENT_ID = const DOMAIN = envConfig.AWS_COGNITO_DOMAIN //envConfig.AWS_COGNITO_DOMAIN const IDENTITY_POOL_ID =

const auth = { ssr: true, mandatorySignId: mandatorySignId, region: REGION, userPoolId: POOL_ID, userPoolWebClientId: CLIENT_ID, identityPoolId: IDENTITY_POOL_ID, }; return auth }

Amplify.configure({ Auth: getCognitoAuth() })

const user = await Auth.signIn({ username: values.personId, password: "" })

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

const auth = { ssr: true, mandatorySignId: mandatorySignId, region: REGION, userPoolId: POOL_ID, userPoolWebClientId: CLIENT_ID, identityPoolId: IDENTITY_POOL_ID, }; return auth }

Additional configuration

{ "UserPool": { "Id": , "Name": , "Policies": { "PasswordPolicy": { "MinimumLength": 8, "RequireUppercase": false, "RequireLowercase": false, "RequireNumbers": false, "RequireSymbols": false, "TemporaryPasswordValidityDays": 7 } }, "LambdaConfig": { "DefineAuthChallenge": , "CreateAuthChallenge":, "VerifyAuthChallengeResponse": , }, "LastModifiedDate": "2021-11-08T10:38:55.826000+02:00", "CreationDate": "2021-10-28T13:34:33.096000+03:00", "SchemaAttributes": [ { "Name": "sub", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": false, "Required": true, "StringAttributeConstraints": { "MinLength": "1", "MaxLength": "2048" } }, { "Name": "name", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "given_name", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "family_name", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "middle_name", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "nickname", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "preferred_username", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "profile", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "picture", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "website", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "email", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "email_verified", "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false }, { "Name": "gender", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "birthdate", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "10", "MaxLength": "10" } }, { "Name": "zoneinfo", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "locale", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "phone_number", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "phone_number_verified", "AttributeDataType": "Boolean", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false }, { "Name": "address", "AttributeDataType": "String", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "StringAttributeConstraints": { "MinLength": "0", "MaxLength": "2048" } }, { "Name": "updated_at", "AttributeDataType": "Number", "DeveloperOnlyAttribute": false, "Mutable": true, "Required": false, "NumberAttributeConstraints": { "MinValue": "0" } } ], "VerificationMessageTemplate": { "DefaultEmailOption": "CONFIRM_WITH_CODE" }, "MfaConfiguration": "OFF", "EstimatedNumberOfUsers": 6, "EmailConfiguration": { "EmailSendingAccount": "COGNITO_DEFAULT" }, "UserPoolTags": {}, "AdminCreateUserConfig": { "AllowAdminCreateUserOnly": false, "UnusedAccountValidityDays": 7 }, "Arn": } }

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

timorss commented 2 years ago

Same happens to me

Did someone solve it?

tannerabread commented 2 years ago

@tl1993 @timorss Are either of you still experiencing this issue?

tannerabread commented 1 year ago

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you.

Thank you!