This document guides you through adding a password reset functionality to your site. This functionality is complex and is a good demonstration of the different features on Insites.
To follow the steps in this tutorial, you must understand the required directory structure for your codebase, have a test email set up, and understand the concept of pages, users, Tables, Database Fields, and Permissions. In addition, you must know how to create a form.
Resetting a password is a six-step process:
app/schema/reset_password.yml
If you're using modules, make sure to adjust paths accordingly, for example,
app/forms/recover_password.liquid
Create a GraphQL query to check if the provided email address has a user associated with it in the database. If yes, generate a temporary token to authenticate the request.
app/graphql/generate_user_temporary_token.graphql
If the user exists, store the value of the generated token in a field (Property) associated with the default profile.
app/user_profile_types/default.yml
This way, you can ensure that only the most recent token can be used. To store the actual value, create a GraphQL mutation.
app/graphql/update_password_token.graphql
Each GraphQL mutation has an associated form configuration; in this case, it's
app/forms/update_password_token.liquid
app/emails/send_recover_password.liquid
The email relies on a GraphQL query called
app/graphql/get_user_with_password_token.graphql
Create a page as an entry point to the workflow.
app/views/pages/recover_password.liquid
app/views/pages/reset-password.liquid
The above page is used to check if the provided token is valid and fetch the user's id based on the email provided in the parameter. Re-use the GraphQL query created earlier.
The page below embeds the form to reset the password.
app/forms/reset_password.liquid
To re-render the previous page, forward the email and token parameters from the email if the password validation fails. The token is also used in an Authorization Policy, where the user is authenticated with this token to ensure they can't change another user's password. You can add more rules to the password field by
Create this Authorization Policy:
app/authorization_policies/token_is_valid.liquid
If the user confirms a valid password, the system changes the password and redirects the user to the
Temporary token will be invalidated on user password change.
Congratulations! You know how to build a password reset process. Now you can learn about accessing user data: Accessing Authenticated User Data.
Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.