mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 03:45:06 +03:00
Update password reset details in new ref docs
This commit is contained in:
1 parent
a732b47acf
commit
89d1581b75
1 file changed
+31
-16
@@ -478,27 +478,42 @@ pages:
|
||||
title: 'resetPasswordForEmail()'
|
||||
$ref: '@supabase/gotrue-js.GoTrueClient.resetPasswordForEmail'
|
||||
notes: |
|
||||
Sends a password reset request to an email address.
|
||||
|
||||
When the user clicks the password reset link in the email, they are redirected to the [`SITE_URL`](https://supabase.com/docs/reference/auth/config#site_url) by default. You can modify your `SITE_URL` or add additional redirect URLs in [your project](https://app.supabase.com/project/_/auth/settings).
|
||||
|
||||
`<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 [update the user](/docs/reference/javascript/next/auth-updateuser) as follows:
|
||||
|
||||
Sends a reset request to an email address.
|
||||
When the user clicks the reset link in the email they are redirected back to your application.
|
||||
Prompt the user for a new password and call `auth.update()`:
|
||||
```js
|
||||
const { error, data } = await supabase.auth.updateUser({ password : new_password })
|
||||
const { data, error } = await supabase.auth
|
||||
.update({ password: new_password })
|
||||
```
|
||||
examples:
|
||||
- name: Reset password
|
||||
isSpotlight: true
|
||||
- name: Reset Password (React)
|
||||
isSpotlight: false
|
||||
js: |
|
||||
```js
|
||||
const { error, data } = await supabase.auth.resetPasswordForEmail(email, options: {
|
||||
redirectTo: 'https://example.com/update-password',
|
||||
})
|
||||
/**
|
||||
* Step 1: Send the user an email to get a password reset token.
|
||||
* This email contains a link which sends the user back to your application.
|
||||
*/
|
||||
const { data, error } = await supabase.auth
|
||||
.resetPasswordForEmail('user@email.com')
|
||||
|
||||
/**
|
||||
* Step 2: Once the user is redirected back to your application,
|
||||
* ask the user to reset their password.
|
||||
*/
|
||||
useEffect(() => {
|
||||
supabase.auth.onAuthStateChange(async (event, session) => {
|
||||
if (event == "PASSWORD_RECOVERY") {
|
||||
const newPassword = prompt("What would you like your new password to be?");
|
||||
const { data, error } = await supabase
|
||||
.auth
|
||||
.update({ password: newPassword })
|
||||
|
||||
if (data) alert("Password updated successfully!")
|
||||
if (error) alert("There was an error updating your password.")
|
||||
}
|
||||
})
|
||||
}, [])
|
||||
```
|
||||
|
||||
auth.admin.generateLink():
|
||||
|
||||
Reference in new issue
Block a user