'AWS Cognito | On globalSignOut user is not authenticated

When a user is logging out of AWS Cognito using globalSignOut, I'm getting a "User is not authenticated" error. To authenticate a user I need to pass the auth details (Username, Password) to authenticateUser. I do not have access to the users password when logging out. Is there a way to set the user as authenticated upon login to avoid using authenticateUser when logging out?



Solution 1:[1]

The Solutions was to use cognitoUser.getSession before running the globalSignOut

 let poolData = {
      UserPoolId: cognitoUserPoolId,
      ClientId: cognitoAppClientId
 };

let userPool = new CognitoUserPool(poolData);
let userData = { Username: username, Pool: userPool };

let cognitoUser = new CognitoUser(userData);

cognitoUser.getSession((err:any, result:any)=>{
  if(result){
    cognitoUser.globalSignOut({
      onSuccess: (result) => {
        //success
      },
      onFailure: (err) => {
        //err;
      },
    });
  }
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1