aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.44k stars 2.13k forks source link

Allow Auth.forgotPassword to accept a 'customCode' argument for testing. #10898

Closed cjsilva-umich closed 1 year ago

cjsilva-umich commented 1 year ago

Is this related to a new or existing framework?

React

Is this related to a new or existing API?

Authentication

Is this related to another service?

Cognito

Describe the feature you'd like to request

I think that it would be helpful if we could pass in a code to Auth.forgotPassword so that testing libraries (Cypress in my case) can run tests for the Forgot Password flow. That, or be able to retrieve the confirmation code from some front-end function so that testing can be done.

Describe the solution you'd like

Either change the Auth.forgotPassword method to accept a custom code, like:

const customAuthServices = {
  async handleForgotPassword({username: string, customCode: number}) {
    Auth.forgotPassword(username, customCode)
      .then((data) => console.log("data:", data))
      .catch((error) => console.error("error:", error));
  }
};
<Authenticator services={customAuthServices} />

or the object returned by Auth.forgotPassword ("data" in the above scenario) should contain the code.

Describe alternatives you've considered

I have been unable to find any documentation or online q/a that indicates that it's possible to get the confirmation code (or supply one) without the email, which makes testing impossible.

Additional context

No response

Is this something that you'd be interested in working on?

cwomack commented 1 year ago

Hello @cjsilva-umich 👋. Unfortunately, this won’t be a feature that we would want to implement in our public facing APIs. However, you may be able to implement this on your own by leveraging the custom sender lambda triggers via Amazon Cognito user pools and then send the code to something like DynamoDB to be retrieved from there (rather than sending the email).

While I'll be closing this issue, we appreciate you taking the time to come up with this idea to improve Amplify further.