AWS Cognito Token Issues

0

try { var data = await Auth.signIn(values.email, values.password); console.log("data",data);

  if (data.signInUserSession) {
    const accessToken = data.signInUserSession.accessToken.jwtToken;
    console.log("Access Token: " + accessToken);
  } else {
    console.log("Authentication succeeded but no user session found.")
  }
} catch (error) {
  console.error("Authentication error:", error);
}


setRemember(values.remember);
// login(values);

};

I have called Cognito for login. login succeeds but token not yet return, like id token , refresh token, ect... and i am not using any lambda tragger.

i got the messge like : Authentication succeeded but no user session found.

1 Answer
0

Hello,

I understand that Cognito JWT tokens are not returned when Amplify makes the REST API call Auth.signIn().

With Auth.signIn() API you pass the username and password to the signIn method of the Auth class to enable username and password sign-in.

[+] Sign In a user : https://docs.amplify.aws/lib/auth/emailpassword/q/platform/js/#sign-in

Auth.signIn() returns a CognitoUser Object as defined in the API Docs.

[+] API docs: https://aws-amplify.github.io/amplify-js/api/classes/authclass.html#signin

The user variable is a CognitoUser Object, which represents a single CognitoUser. The JWT Token in stored in the CognitoUser.CognitoUserSession attribute .

[+] CognitoUser : https://aws-amplify.github.io/aws-sdk-android/docs/reference/com/amazonaws/mobileconnectors/cognitoidentityprovider/CognitoUser.html

The API call updates the CognitoUser with session and token JWT. After Auth.signIn() the user Object would have been updated if AWS issued tokens. After successfully authenticating a user, Amazon Cognito issues JSON web tokens (JWT) that you can use to secure and authorize access to your own APIs, or exchange for AWS credentials.

That being said, to further look into this issue more closely, if you would like to do a resource based troubleshooting, please raise a support case with AWS for further information. If a support case has already been created please be assured that we will get back to you and assist you in the best way possible.

[+] https://console.aws.amazon.com/support/home#/case/create

AWS
Shreeya
answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions