Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add more details for the password reset

Copple2c5389a59819
diff --git a/web/spec/supabase.yml b/web/spec/supabase.yml
index 148c93c5222..6c747b8148e 100644
--- a/web/spec/supabase.yml
+++ b/web/spec/supabase.yml
@@ -689,17 +689,13 @@ pages:
notes: |
Sends a reset request to an email address.
- When the user clicks the reset link in the email they will be forwarded to:
+ When the user clicks the reset link in the email they will be forwarded back to your application.
- `<SITE_URL>#access_token=x&refresh_token=y&expires_in=z&token_type=bearer&type=recovery`
-
- Your app must detect `type=recovery` in the fragment and display a password reset form to the user.
-
- You should then use the access_token in the url and new password to update the user as follows:
+ You should then use the `auth.update()` function to create a new password that the user supplies:
```js
- const { error, data } = await supabase.auth.api
- .updateUser(access_token, { password : new_password })
+ const { error, data } = await supabase.auth
+ .update({ password: new_password })
```
examples:
- name: Reset password
@@ -709,6 +705,35 @@ pages:
const { data, error } = await supabase.auth.api
.resetPasswordForEmail('[email protected]')
```
+ - name: React example
+ isSpotlight: false
+ js: |
+ ```js
+ /**
+ * Step 1: Send the user an email to get a password reset token.
+ * This email will contain a link which will send the user back to your application.
+ */
+ const { data, error } = await supabase.auth
+ .resetPasswordForEmail('[email protected]')
+
+ /**
+ * Step 2: Once the user is redirected back to your application,
+ * you can ask the user to reset their password.
+ */
+ useEffect(() => {
+ supabase.auth.onAuthStateChange(async (event, session) => {
+ if (event == "PASSWORD_RECOVERY") {
+ const newPass = prompt("What would you like your new password to be?");
+ const { data, error } = await supabase
+ .auth
+ .update({ password: newPass })
+
+ if (data) alert("Password updated successfully!")
+ if (error) alert("There was an error updating your password.")
+ }
+ })
+ }, [])
+ ```
auth.api.generateLink():
title: 'generateLink()'