Skip to main content
Version: v2 RC

resetPasswordForEmail()

Sends a password reset request to an email address.

const { data, error } = await supabase.auth.resetPasswordForEmail(email, {
redirectTo: 'https://example.com/update-password',
})

Parameters

  • emailrequiredstring

    The email address of the user.

  • optionsrequiredobject

    No description provided.

      Properties
    • captchaTokenoptionalstring

      Verification token received when the user completes the captcha on the site.

    • redirectTooptionalstring

      The URL to send the user to after they click the password reset link.

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():

const { data, error } = await supabase.auth
.updateUser({ password: new_password })

Examples

Reset password

const { data, error } = await supabase.auth.resetPasswordForEmail(email, {
redirectTo: 'https://example.com/update-password',
})

Reset password (React)

/**
* 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
.updateUser({ password: newPassword })

if (data) alert("Password updated successfully!")
if (error) alert("There was an error updating your password.")
}
})
}, [])