User is not authenticated message is getting in the response while i'm trying to do updateUserAttribute, deleteUser (authenticated user), verifyUserAttribute, after succesful login authenticateUser method is called and tokens are generated.

Following is my authenticateUser Code:

import { CognitoUser, AuthenticationDetails } from "amazon-cognito-identity-js";
import Pool from "./UserPool";
const AWS = require('aws-sdk/global');

const authenticate = async (Username, Password) => (
    await new Promise((resolve, reject) => {
      const user = new CognitoUser({ Username, Pool });
      const authDetails = new AuthenticationDetails({ Username, Password });

      user.authenticateUser(authDetails, {
        onSuccess: data => {
          console.log('onSuccess:', data);
          AWS.config.region = 'us-east-1';

          AWS.config.credentials = new AWS.CognitoIdentityCredentials({
            IdentityPoolId: 'us-east-1:********-****-****-****-************', // your identity pool id here
            Logins: {
              // Change the key below according to the specific region your user pool is in.
              'cognito-idp.us-east-1.amazonaws.com/us-east-1_xxxxxxxxx': data
                .getIdToken()
                .getJwtToken(),
            },
          });
          //refreshes credentials using AWS.CognitoIdentity.getCredentialsForIdentity()
          AWS.config.credentials.refresh(error => {
            if (error) {
              console.error('refresh err: ',error);
            } else {
              // Instantiate aws sdk service objects now that the credentials have been updated.
              // example: var s3 = new AWS.S3();
              console.log('Successfully logged!');
            }
          });
          
          resolve(data);
        },

        onFailure: err => {
          console.error('onSignInFailure:', err);
          reject(err);
        },

        newPasswordRequired: data => {
          console.log('newPasswordRequired:', data);
          resolve(data);
        }
      });
    })
)
export default authenticate;

Any steps that I'm missing after generating tokens and storing credentials in AWS.config.credentials

0

There are 0 best solutions below