-
Notifications
You must be signed in to change notification settings - Fork 0
Reset Password Flow
This is the overall workflow for a User to reset their password:
-
user goes to a page on the front end site which contains a form with a single text field, they type their email address into this field and click a button to submit the form
-
that form submission sends a request to the API:
POST /auth/passwordwith some parameters:email(the email supplied in the field) &redirect_url(a page in the front end site that will contain a form withpasswordandpassword_confirmationfields) -
the API responds to this request by generating a
reset_password_tokenand sending an email (thereset_password_instructions.html.erbfile from devise) to the email address provided within theemailparameter- we need to modify the
reset_password_instructions.html.erbfile to point to the API:GET /auth/password/edit - for example, if you have your API under the
api/v1namespaces:<%= link_to 'Change my password', edit_api_v1_user_password_url(reset_password_token: @token, config: message['client-config'].to_s, redirect_url: message['redirect-url'].to_s) %>(I came up with thislink_toby referring to this line)
- we need to modify the
-
the user clicks the link in the email, which brings them to the 'Verify user by password reset token' endpoint (
GET /password/edit) -
this endpoint verifies the user and redirects them to the
redirect_urlif they are who they claim to be (if theirreset_password_tokenmatches a User record) -
this
redirect_urlis a page on the frontend which contains apasswordandpassword_confirmationfield -
the user submits the form on this frontend page, which sends a request to API:
PUT /auth/passwordwith thepasswordandpassword_confirmationparameters. In addition headers need to be included from the url params. A side note, ensure that the header names follow the convention outlined inconfig/initializers/devise_token_auth.rb; at this time of writing it is:uid,clientandaccess-token. -
the API changes the user's password and responds back with a success message
-
the front end needs to manually redirect the user to its login page after receiving this success response
-
the user logs in