Closed MattyK14 closed 7 years ago
are you running react-native-aws-cognito-js version 0.0.4 ?
I was not. So I should be able to use this to not force the user to enter their credentials each time they open the app?
@MattyK14 how were you able to read cognitoUser from MemoryStorage ?
I'm using your code snippet, but it returns null
export const checkIfLoggedIn = () => {
return (dispatch) => {
dispatch({ type: DO_NOTHING });
var userPool = new CognitoUserPool(appConfig);
var cognitoUser = userPool.getCurrentUser();
console.log(cognitoUser);
if (cognitoUser != null) {
cognitoUser.getSession(function(err, session) {
if (err) {
console.log(err);
return;
}
console.log('session validity: ' + session.isValid());
// NOTE: getSession must be called to authenticate user before calling getUserAttributes
cognitoUser.getUserAttributes(function(err, attributes) {
if (err) {
// Handle error
} else {
// Do something with attributes
console.log(attributes);
}
});
// in the future, you can insert here code to set token to access aws resources based on user access
Actions.main({ type: 'reset' });
});
}
}
};
@vvavepacket I was, but it was super inconsistent and had to shelf it for now. Sometimes cognitoUser would come back null
.
From the
README.md
I'm using:or
I played around with the example application without a crash, the result logs
'SUCCESS'
.Here's an example snippet of where I've tried to use it: