I am using Cognito to sign in users to a react-native app. I am using my own sign in flow and using Cognito as the identity provider/pool.
Auth.currentSession works properly.Auth.currentSession works. Auth.currentSession works for the next 60 minutes. Auth.currentSession to work again.[DEBUG] 46:35.287 AuthClass - getting user data failed: Error: User is not authenticated at CognitoUser.getUserData
Auth.currentSession correctly retrieves the current session.Auth.currentSession fails after what appears to be the life of the accessToken. Although the refresh succeeds, the Auth.currentSession function itself fails.
From what I can tell there are several methods to check whether the user is authenticated. There is little documentation on which one to use when. I have tried currentSession, currentAuthenticatedUser, and currentUserPoolUser all to no avail.
@aws-amplify/auth: ^1.0.4 and ^1.0.5-unstable.3
@aws-amplify/core: ^1.0.3
amazon-cognito-identity-js: ^2.0.19
aws-sdk: ^2.283.1
react-native": ^0.56.0
// auth loading component, mounted on initial app open.
async componentDidMount() {
try {
await Auth.currentSession(); // refresh tokens if necessary, failing on cold start.
Navigation.reset('Authenticated');
} catch(e) {
Navigation.reset('Unauthenticated');
}
}
// from my services.
let creds = await Auth.currentUserCredentials(); // refresh tokens if necessary
new AWS.S3({
credentials: Auth.essentialCredentials(creds),
});
I am also getting this error. It looks like its failing to refresh although I am not sure if it is related. This occurs from the call in services. It does not cause credentials to be invalid or await Auth.currentUserCredentials to throw.
[DEBUG] 59:11.25 AuthClass - getting current credntials
ConsoleLogger.js:84 [DEBUG] 59:11.28 Credentials - getting credentials
ConsoleLogger.js:84 [DEBUG] 59:11.30 Credentials - picking up credentials
ConsoleLogger.js:84 [DEBUG] 59:11.32 Credentials - getting new cred promise
ConsoleLogger.js:84 [DEBUG] 59:11.34 Credentials - checking if credentials exists and not expired
ConsoleLogger.js:84 [DEBUG] 59:11.36 Credentials - need to get a new credential or refresh the existing one
ConsoleLogger.js:84 [DEBUG] 59:11.61 AuthClass - Getting current user credentials
ConsoleLogger.js:100 Object {[DEBUG] 59:11.64 AuthClass - failed to get or parse item aws-amplify-federatedInfo: SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>) at AuthClass.currentUserCredentials at Credentials._keepAlive at Credentials._pickupCredentials at Credentials._pickupCredentials at AuthClass.currentCredentials}
I'm seeing the same exact issue. It seems like it's a recent change since it wasn't there a couple of weeks ago.
Related to #1380
Faced same issue, definitely related to recent changes, since it isn't present in 0.4.1
@powerful23
This is still not resolved correctly. In 1.0.8 the following bug is present:
When the app is totally closed for more than 60 minutes and then reopened the Auth.currentAuthenticatedUser() no longer throws an error though it does not return the user attributes.
This is what is returned:
{
authenticationFlowType: [xxx],
client: {
endpoint: https://cognito-idp.us-east-1.amazonaws.com/,
userAgent: aws-amplify/0.1.x react-native
},
deviceKey: us-east-1_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,
pool: {
advancedSecurityDataCollectionFlag: True,
client: {},
clientId: xxxxxxxxxxxxxxxxxxxxxxxxxx,
userPoolId: us-east-1_XXXXXXXXX
},
Session: None,
signInUserSession: None,
username: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
}
I expect the user attributes to be returned. I hade to downgrade my aws-amplify version to "0.4.7" to make this work again.
@andidev You can find user attributes in Auth.currentUserInfo
Okey I will try that though still this feels like a bug. I don't understand why it should not return the attributes in only this case. In all other cases it returns the attribute.
@andidev will try to reproduce it
Any update? looks like issue still exist.
Most helpful comment
Any update? looks like issue still exist.