Search code examples
javascriptnode.jscoffeescriptamazon-cognito

How to delete amazon cognito user?


I want to delete cognito user using my nodejs application.
Example

cognitoUser.deleteUser (err, result) ->
  if err
    reject err
  resolve result

when i try to delete cognito user error throws as follows

Error: User is not authenticated

cognitoUser.deleteUser is used by an authenticated user to delete himself but i want to delete all users using super user

Please give me some idea to solve this problem.


Solution

  • You can use the main aws javascript SDK and call the adminDeleteUser operation. It is an authenticated operation and it will require developer credentials for you to call it.

    https://github.com/aws/aws-sdk-js/blob/master/apis/cognito-idp-2016-04-18.normal.json#L100

    var aws = require('aws-sdk');
    var CognitoIdentityServiceProvider = aws.CognitoIdentityServiceProvider;
    var client = new CognitoIdentityServiceProvider({ apiVersion: '2016-04-19', region: 'us-east-1' });
    
    //now you can call adminDeleteUser on the client object