From 89d1581b7559bbd4ea02efe702ff2f8a1712f5fd Mon Sep 17 00:00:00 2001 From: dannykng Date: Tue, 30 Aug 2022 15:20:30 -0700 Subject: [PATCH] Update password reset details in new ref docs --- spec/supabase_js_v2_legacy.yml | 47 ++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/spec/supabase_js_v2_legacy.yml b/spec/supabase_js_v2_legacy.yml index 0925a05d134..450204cde24 100644 --- a/spec/supabase_js_v2_legacy.yml +++ b/spec/supabase_js_v2_legacy.yml @@ -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). - - `#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():