amazon-archives / amazon-cognito-identity-js

Amazon Cognito Identity SDK for JavaScript
Other
985 stars 454 forks source link

How to use 'sync' function in 'StorageHelper-rn.js' to decide a user already logged in or not[react-native] #615

Closed ma2kutty closed 6 years ago

ma2kutty commented 6 years ago

I see a 'sync' function in 'StorageHelper-rn.js' which stores the necessary credentials in AsyncStorage (provided by react native). How to use this feature?

Current scenario

  1. User Logs in (all fine)
  2. Exit the app (not logout)
  3. Opens app again. Not recognized as earlier logged in user, since 'userPool.getCurrentUser()' returns null Can somebody help me with this?
ma2kutty commented 6 years ago

I have done like below, is this the right way, since I could not find any documentation in these lines. The below lines are working though.

userPool.storage.sync(function(err, result){ if(err){ //Handle error
} else if(result == "SUCCESS"){ if(userPool.getCurrentUser()) { //user logged in //navigate to home } else { //new user //navigate to login } }

minbi commented 6 years ago

You are correct.