Jay Hyber
Jay Hyber

Reputation: 321

Cognito Forgot Password : Username is also forgotten

I implemented the forgot password flow in my react app, and it works find IF the user haven't forget his username. Problem now is he also forgot his username. In documentation, username is included as a required field.

var params = {
  ClientId: 'STRING_VALUE', /* required */
  Username: 'STRING_VALUE', /* required */
  AnalyticsMetadata: {
    AnalyticsEndpointId: 'STRING_VALUE'
  },
  ClientMetadata: {
    '<StringType>': 'STRING_VALUE',
    /* '<StringType>': ... */
  },
  SecretHash: 'STRING_VALUE',
  UserContextData: {
    EncodedData: 'STRING_VALUE'
  }
};
cognitoidentityserviceprovider.forgotPassword(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

How to solve this issue?

Upvotes: 1

Views: 348

Answers (1)

hephalump
hephalump

Reputation: 6164

There are a few ways you could potentially do this, one potential way would be to allow users to reset passwords using their email address.

This would be a two step process for your function. First, when the user submits their email address you will use the ListUsers API method with a filter applied on the email attribute. The response will include the username which you can then use in the second step which would be to send a password reset email.

You can read more about the ListUsers API method here in the AWS docs, and about searching for users using that method in the AWS docs here.

Upvotes: 1

Related Questions