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

Aws Amplify Won't stay signed in #10762

Closed Arnav7501 closed 1 year ago

Arnav7501 commented 1 year ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

``` # Put output below this line System: OS: macOS 12.0.1 CPU: (8) arm64 Apple M1 Memory: 138.02 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.17.0 - /usr/local/bin/node npm: 9.1.2 - ~/lbnapp_new/node_modules/.bin/npm Browsers: Chrome: 108.0.5359.98 Safari: 15.1 npmPackages: @angular/cli: ^15.0.1 => 15.0.1 @babel/core: ^7.18.6 => 7.20.5 (7.9.0) @expo/config-plugins: ^5.0.0 => 5.0.4 @expo/webpack-config: ^0.17.0 => 0.17.3 @react-native-async-storage/async-storage: ~1.17.3 => 1.17.11 @react-native-community/netinfo: 9.3.0 => 9.3.0 @react-native-picker/picker: 2.4.2 => 2.4.2 @react-navigation/bottom-tabs: ^6.5.0 => 6.5.0 @react-navigation/native: ^6.0.12 => 6.0.16 @react-navigation/native-stack: ^6.8.0 => 6.9.4 HelloWorld: 0.0.1 amazon-cognito-identity-js: ^5.2.10 => 5.2.12 aws-amplify: ^4.3.33 => 4.3.43 aws-amplify-react-native: ^6.0.8 => 6.0.8 dependencies: ^0.0.1 => 0.0.1 expo: ^46.0.16 => 46.0.17 expo-clipboard: ~3.1.0 => 3.1.0 expo-image-picker: ~13.3.1 => 13.3.1 expo-splash-screen: ~0.16.2 => 0.16.2 expo-status-bar: ~1.4.0 => 1.4.2 expo-updates: ~0.14.7 => 0.14.7 gradle: ^1.2.4 => 1.2.4 graphql: ^16.6.0 => 16.6.0 (15.8.0) hermes-inspector-msggen: 1.0.0 ini: ^1.3.5 => 1.3.8 (3.0.1) inquirer: ^6.5.1 => 6.5.2 (8.2.4) install: ^0.13.0 => 0.13.0 npm: ^9.1.2 => 9.1.2 react: 18.0.0 => 18.0.0 react-dom: 18.0.0 => 18.0.0 react-hook-form: ^7.37.0 => 7.39.7 react-live-clock: ^6.0.6 => 6.1.0 react-native: 0.69.6 => 0.69.6 react-native-get-random-values: ~1.8.0 => 1.8.0 react-native-really-awesome-button: ^2.0.3 => 2.0.3 react-native-safe-area-context: 4.3.1 => 4.3.1 react-native-screens: ~3.15.0 => 3.15.0 react-native-web: ~0.18.7 => 0.18.10 react-native-webview: 11.23.0 => 11.23.0 uuid: ^9.0.0 => 9.0.0 (3.4.0, 3.3.2, 8.3.2, 7.0.2, 7.0.3) whatwg-fetch: ^2.0.4 => 2.0.4 (3.6.2) npmGlobalPackages: @angular/cli: 15.0.1 @aws-amplify/cli: 10.5.1 @react-native-picker/picker: 2.4.8 eas-cli: 2.8.0 expo-cli: 6.0.8 gradle: 1.2.4 ios-deploy: 1.11.4 n: 9.0.0 npm: 9.1.3 react-native-cli: 2.0.1 searchable-flatlist: 0.0.4 tls-test: 1.0.0 yarn: 1.22.19 ```

Describe the bug

User gets signed in succesfully, but on refreshing page or closing app the user gets signed out. If I run log authuser = await Auth.currentAuthenticatedUser({bypassCache :true}), i get an error that the user is not authenticated. Running on expo react native.

Expected behavior

Was expecting the user to stay signed in, and not get signed out on closing the app or refreshing

Reproduction steps

Unsure how to reproduce, seems to only be an error with my system.

Code Snippet

// Put your code below this line.

Log output

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

aws-exports.js

/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "us-west-1",
    "aws_cognito_identity_pool_id": "us-west-1:c5ca7116-4e3c-4119-bac9-840c558ccde5",
    "aws_cognito_region": "us-west-1",
    "aws_user_pools_id": "us-west-1_KyYUYtU9h",
    "aws_user_pools_web_client_id": "70lpo834a3snibile7ksa4jp99",
    "oauth": {},
    "aws_cognito_username_attributes": [],
    "aws_cognito_social_providers": [],
    "aws_cognito_signup_attributes": [
        "NAME",
        "EMAIL"
    ],
    "aws_cognito_mfa_configuration": "OFF",
    "aws_cognito_mfa_types": [
        "SMS"
    ],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 7,
        "passwordPolicyCharacters": []
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL"
    ],
    "aws_appsync_graphqlEndpoint": "https://uzg65om2zndhtnwfa4qwnrgc7a.appsync-api.us-west-1.amazonaws.com/graphql",
    "aws_appsync_region": "us-west-1",
    "aws_appsync_authenticationType": "API_KEY",
    "aws_appsync_apiKey": "da2-zydyqxmcrnhojctvdnuijbaata",
    "aws_user_files_s3_bucket": "socialmediaapp-storage-8135690111043-staging",
    "aws_user_files_s3_bucket_region": "us-west-1"
};

export default awsmobile;

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

tannerabread commented 1 year ago

Hi @Arnav7501 How have you verified that it's only a problem with your system?

Also do you have any custom config passed to Amplify.configure in your app or do you just pass it the contents of aws-exports?

Arnav7501 commented 1 year ago

Thanks for the reply, The reason I'm confused is that on other applications where i ran the exact same authentication system the user has stayed signed in, but on this particular program the user gets logged out, leading me to believe its specific to my program for some reason. In Amplify.configure, i just pass the contents of aws-exports

tannerabread commented 1 year ago

Interesting, were the other applications also React Native?

Did you import the entire amplify project with amplify pull --appId YOUR_APP_ID --envName YOUR_ENV_NAME or create a new amplify project via amplify init and then import the auth resources via amplify import auth?

Arnav7501 commented 1 year ago

I created a new project via amplify init and used the same authentication, username and password. In both, I just use Auth.signIn to log in and it works, but on refreshing if i log Auth.currentAuthenticatedUser its logged out for god knows why

tannerabread commented 1 year ago

@Arnav7501 what device are you testing this on? Or is it showing up on both iOS and android?

tannerabread commented 1 year ago

Just copying your comment from discord to consolidate and be clear:

You are running the following:

const authuser = await Auth.currentAuthenticatedUser({bypassCache :true})
setUser(authuser)
console.log("auth",authuser)

And getting the error the user is not authenticated

Are you running these commands within an async function? I tried this on an iOS emulator and have not been able to reproduce so far

Arnav7501 commented 1 year ago

problem is on both ios and android for the program, i'll link a screenrecording of the situation

Arnav7501 commented 1 year ago

https://drive.google.com/file/d/1RjffJHRNm8HcNOZWcyJwbBcrSGaSVL3c/view?usp=sharing

If the user is authenticated, It then moves directly into the app, otherwise it stays at the signin screen, in the recording you can see once i refresh it automatically signs out the user.

tannerabread commented 1 year ago

Interesting, that shouldn't be happening. I'm able to close my app completely after logging in and stay signed in.

We have a known issue with duplicate Amplify instances being created if versions are mismatched, so can you follow the instructions here and let me know what your output is for that? Sometimes the multiple instances causes a user to be logged in on one but logged out on the other and cause errors like you are seeing.

Another side note that I don't think would be effecting your app but I want to clear up, I don't think you should need the package aws-amplify-react-native as this is just for UI. There is a dev preview out for new React Native UI components and that package is on its way to deprecation. We have been trying to clean up the docs and remove the call to install that package, do you remember where you saw that?

Arnav7501 commented 1 year ago

i think i'm going to have to throw in the towel,, i upgraded amplify to the latest version through the yarn command, but it destroyed my project, Now i get this error, ERROR [ERROR] 41:10.991 DataStore - Models were generated with an unsupported version of codegen. Codegen artifacts are from an unknown version, whereas ^3.2.0 is required. Update to the latest CLI and run 'amplify codegen models'. ERROR Error: Models were generated with an unsupported version of codegen. Codegen artifacts are from an unknown version, whereas ^3.2.0 is required. Update to the latest CLI and run 'amplify codegen models'.

running amplify codegen models does not fix the problem, and it simply won't go away.

Thanks for all your time, if you have a solution to the above error i would really appreciate it, but its fine either way

tannerabread commented 1 year ago

Don't give up yet, if it is a problem with our library we can figure it out. I am going to reach out on discord and try to help you through this

tannerabread commented 1 year ago

Related to the error with the project, you should be able to remove your node_modules folder and revert back to a previous version and run yarn again to go back to where you were before.

For that specific DataStore error, there were changes released in v5.0.0 related to codegen's error messages. And related documentation for upgrading to v5+ if you would like to keep the latest version

tannerabread commented 1 year ago

@Arnav7501 you might find this stackoverflow thread helpful.

From what I read it seems to be either out of date or mismatched versions from the CLI, there are a few suggestions in the comments on how to resolve the 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 are 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!

Arnav7501 commented 1 year ago

yeah i just gave up, the incident is so isolated its not worth pursuing

tannerabread commented 1 year ago

I'm sorry to hear that, especially knowing you are one of our discord family. We hope to be able to help better next time

Arnav7501 commented 1 year ago

no problem, you've been more helpful than 99% of people I've came across