resetPasswordForEmail()
Sends a password reset request to an email address.
1const { data, error } = await supabase.auth.resetPasswordForEmail(email, {
2 redirectTo: 'https://example.com/update-password',
3})
Parameters#
emailrequired
string
The email address of the user.
optionsrequired
object
No description provided.
captchaTokenoptional
string
Verification token received when the user completes the captcha on the site.
redirectTooptional
string
The URL to send the user to after they click the password reset link.
Properties
Notes#
Sends a password 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.updateUser()
:
1const { data, error } = await supabase.auth
2 .updateUser({ password: new_password })
Examples#
Reset password#
1const { data, error } = await supabase.auth.resetPasswordForEmail(email, {
2 redirectTo: 'https://example.com/update-password',
3})
Reset password (React)#
1/**
2 * Step 1: Send the user an email to get a password reset token.
3 * This email contains a link which sends the user back to your application.
4 */
5const { data, error } = await supabase.auth
6 .resetPasswordForEmail('user@email.com')
7
8/**
9 * Step 2: Once the user is redirected back to your application,
10 * ask the user to reset their password.
11 */
12 useEffect(() => {
13 supabase.auth.onAuthStateChange(async (event, session) => {
14 if (event == "PASSWORD_RECOVERY") {
15 const newPassword = prompt("What would you like your new password to be?");
16 const { data, error } = await supabase.auth
17 .updateUser({ password: newPassword })
18
19 if (data) alert("Password updated successfully!")
20 if (error) alert("There was an error updating your password.")
21 }
22 })
23 }, [])