Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Generate supabase-js v2 ref docs

dannykng9b3d5b0ec2df
diff --git a/apps/reference/_supabase_js/generated/auth-resetpasswordforemail.mdx b/apps/reference/_supabase_js/generated/auth-resetpasswordforemail.mdx
index cda380e0313..d68a4488398 100644
--- a/apps/reference/_supabase_js/generated/auth-resetpasswordforemail.mdx
+++ b/apps/reference/_supabase_js/generated/auth-resetpasswordforemail.mdx
@@ -11,7 +11,7 @@ import TabItem from '@theme/TabItem'
Sends a password reset request to an email address.
```js
-const { error, data } = await supabase.auth.resetPasswordForEmail(email, options: {
+const { data, error } = await supabase.auth.resetPasswordForEmail(email, {
redirectTo: 'https://example.com/update-password',
})
```
@@ -110,17 +110,11 @@ 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 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:
+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()`:
```js
-const { error, data } = await supabase.auth.updateUser({
+const { data, error } = await supabase.auth.updateUser({
password: new_password,
})
```
@@ -130,7 +124,37 @@ const { error, data } = await supabase.auth.updateUser({
### Reset password
```js
-const { error, data } = await supabase.auth.resetPasswordForEmail(email, options: {
+const { data, error } = await supabase.auth.resetPasswordForEmail(email, {
redirectTo: 'https://example.com/update-password',
})
```
+
+### Reset password (React)
+
+```js
+/**
+ * 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(
+)
+
+/**
+ * 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.')
+ }
+ })
+}, [])
+```