resetPasswordForEmail()

Sends a reset request to an email address.

1const { data, error } = await supabase.auth.api.resetPasswordForEmail(
2  'user@email.com'
3)

Parameters#

  • emailrequired
    string

    The email address of the user.

  • optionsrequired
    object

    No description provided.

      Properties
    • captchaTokenoptional
      string

      No description provided.

    • redirectTooptional
      string

      No description provided.

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

1const { data, error } = await supabase.auth.update({
2  password: new_password,
3})

Examples#

Reset password#

1const { data, error } = await supabase.auth.api.resetPasswordForEmail(
2  'user@email.com'
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.api.resetPasswordForEmail(
6  'user@email.com'
7)
8
9/**
10 * Step 2: Once the user is redirected back to your application,
11 * ask the user to reset their password.
12 */
13useEffect(() => {
14  supabase.auth.onAuthStateChange(async (event, session) => {
15    if (event == "PASSWORD_RECOVERY") {
16      const newPassword = prompt("What would you like your new password to be?");
17      const { data, error } = await supabase.auth.update({
18        password: newPassword,
19      })
20
21      if (data) alert("Password updated successfully!")
22      if (error) alert("There was an error updating your password.")
23    }
24  })
25}, [])