Skip to content

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

update auth reference docs

Kang Ming3c36c3bdd841
diff --git a/spec/supabase_js_v2.yml b/spec/supabase_js_v2.yml
index 5860a40b6da..8a570bca50f 100644
--- a/spec/supabase_js_v2.yml
+++ b/spec/supabase_js_v2.yml
@@ -147,7 +147,7 @@ functions:
- To fetch the currently logged-in user, refer to [`getUser()`](/docs/reference/javascript/auth-getuser).
examples:
- id: sign-up
- name: Sign up.
+ name: Sign up
isSpotlight: true
code: |
```js
@@ -157,7 +157,7 @@ functions:
})
```
- id: sign-up-with-additional-user-metadata.
- name: Sign up with additional user metadata.
+ name: Sign up with additional user metadata
isSpotlight: false
code: |
```js
@@ -217,7 +217,7 @@ functions:
- The magic link's destination URL is determined by the [`SITE_URL`](https://supabase.com/docs/reference/auth/config#site_url). You can modify the `SITE_URL` or add additional redirect urls in [your project](https://app.supabase.com/project/_/auth/settings).
examples:
- id: sign-in-with-email
- name: Sign in with email.
+ name: Sign in with email
isSpotlight: true
description: The user will be sent an email which contains either a magiclink or a OTP or both. By default, a given user can only request a OTP once every 60 seconds.
code: |
@@ -227,7 +227,7 @@ functions:
})
```
- id: sign-in-with-sms-otp
- name: Sign in with SMS OTP.
+ name: Sign in with SMS OTP
isSpotlight: false
description: The user will be sent a SMS which contains a OTP. By default, a given user can only request a OTP once every 60 seconds.
code: |
@@ -343,7 +343,7 @@ functions:
const { data: { user } } = await supabase.auth.getUser()
```
- id: get-the-logged-in-user-with-a-custom-access-token-jwt
- name: Get the logged in user with a custom access token jwt.
+ name: Get the logged in user with a custom access token jwt
isSpotlight: false
code: |
```js
@@ -423,7 +423,10 @@ functions:
title: 'onAuthStateChange()'
$ref: '@supabase/gotrue-js.GoTrueClient.onAuthStateChange'
notes: |
- - Types of auth events: `SIGNED_IN`, `SIGNED_OUT`, `TOKEN_REFRESHED`, `USER_UPDATED`, `USER_DELETED`, `PASSWORD_RECOVERY`
+ - Types of auth events: `SIGNED_IN`, `SIGNED_OUT`, `TOKEN_REFRESHED`, `USER_UPDATED`, `PASSWORD_RECOVERY`
+ - Currently, `onAuthStateChange()` does not work across tabs.
+ For instance, in the case of a password reset flow, the original tab which requested for the password reset link will not receive the `SIGNED_IN` and `PASSWORD_RECOVERY` event when the user clicks on the link.
+
examples:
- id: listen-to-auth-changes
name: Listen to auth changes
@@ -434,6 +437,19 @@ functions:
console.log(event, session)
})
```
+ - id: listen-to-password-recovery-events
+ name: Listen to password recovery events
+ code: |
+ ```js
+ supabase.auth.onAuthStateChange((event, session) => {
+ if (event == 'PASSWORD_RECOVERY') {
+ console.log('PASSWORD_RECOVERY', session)
+
+ // show screen to update user's password
+ showPasswordResetScreen(true)
+ }
+ })
+ ```
- id: listen-to-sign-in
name: Listen to sign in
code: |
@@ -466,22 +482,6 @@ functions:
if (event == 'USER_UPDATED') console.log('USER_UPDATED', session)
})
```
- - id: listen-to-user-deleted
- name: Listen to user deleted
- code: |
- ```js
- supabase.auth.onAuthStateChange((event, session) => {
- if (event == 'USER_DELETED') console.log('USER_DELETED', session)
- })
- ```
- - id: listen-to-password-recovery-events
- name: Listen to password recovery events
- code: |
- ```js
- supabase.auth.onAuthStateChange((event, session) => {
- if (event == 'PASSWORD_RECOVERY') console.log('PASSWORD_RECOVERY', session)
- })
- ```
- id: mfa-enroll
title: 'mfa.enroll()'
$ref: '@supabase/gotrue-js.GoTrueMFAApi.enroll'
@@ -621,7 +621,7 @@ functions:
- The `getUserById()` method requires the user's id which maps to the `auth.users.id` column.
examples:
- id: fetch-the-user-object-using-the-access-token-jwt
- name: Fetch the user object using the access_token jwt.
+ name: Fetch the user object using the access_token jwt
isSpotlight: true
code: |
```js
@@ -631,14 +631,26 @@ functions:
- id: list-users
title: 'listUsers()'
$ref: '@supabase/gotrue-js.GoTrueAdminApi.listUsers'
+ notes: |
+ - Defaults to return 50 users per page.
examples:
- id: get-a-full-list-of-users
- name: Get a full list of users.
+ name: Get a full list of users
isSpotlight: true
code: |
```js
const { data: { users }, error } = await supabase.auth.admin.listUsers()
```
+ - id: get-paginated-list-of-users
+ name: Paginated list of users
+ isSpotlight: false
+ code: |
+ ```js
+ const { data: { users }, error } = await supabase.auth.admin.listUsers({
+ page: 1,
+ perPage: 1000
+ })
+ ```
- id: create-user
title: 'createUser()'
$ref: '@supabase/gotrue-js.GoTrueAdminApi.createUser'
@@ -646,7 +658,7 @@ functions:
- To confirm the user's email address or phone number, set `email_confirm` or `phone_confirm` to true. Both arguments default to false.
examples:
- id: create-a-new-user-with-custom-user-metadata
- name: Create a new user with custom user metadata
+ name: With custom user metadata
isSpotlight: true
code: |
```js
@@ -708,12 +720,17 @@ functions:
title: 'resetPasswordForEmail()'
$ref: '@supabase/gotrue-js.GoTrueClient.resetPasswordForEmail'
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()`:
+ - The password reset flow consist of 2 broad steps: (i) Allow the user to login via the password reset link; (ii) Update the user's password.
+ - The `resetPasswordForEmail()` only sends a password reset link to the user's email.
+ To update the user's password, see [`updateUser()`](/docs/reference/javascript/auth-updateuser).
+ - A `SIGNED_IN` and `PASSWORD_RECOVERY` event will be emitted when the password recovery link is clicked.
+ You can use [`onAuthStateChange()`](/docs/reference/javascript/auth-onauthstatechange) to listen and invoke a callback function on these events.
+ - 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 `updateUser()`:
```js
- const { data, error } = await supabase.auth
- .updateUser({ password: new_password })
+ const { data, error } = await supabase.auth.updateUser({
+ password: new_password
+ })
```
examples:
- id: reset-password
@@ -827,7 +844,7 @@ functions:
$ref: '@supabase/gotrue-js.GoTrueAdminApi.updateUserById'
examples:
- id: updates-a-users-email
- name: Updates a user's email.
+ name: Updates a user's email
isSpotlight: false
code: |
```js
@@ -837,7 +854,7 @@ functions:
)
```
- id: updates-a-users-password
- name: Updates a user's password.
+ name: Updates a user's password
isSpotlight: false
code: |
```js
@@ -847,7 +864,7 @@ functions:
)
```
- id: updates-a-users-metadata
- name: Updates a user's metadata.
+ name: Updates a user's metadata
isSpotlight: true
code: |
```js
@@ -857,7 +874,7 @@ functions:
)
```
- id: updates-a-users-app-metadata
- name: Updates a user's app_metadata.
+ name: Updates a user's app_metadata
isSpotlight: false
code: |
```js
@@ -867,7 +884,7 @@ functions:
)
```
- id: confirms-a-users-email-address
- name: Confirms a user's email address.
+ name: Confirms a user's email address
isSpotlight: false
code: |
```js
@@ -877,7 +894,7 @@ functions:
)
```
- id: confirms-a-users-phone-number
- name: Confirms a user's phone number.
+ name: Confirms a user's phone number
isSpotlight: false
code: |
```js
@@ -6943,7 +6960,7 @@ functions:
- Responses are automatically parsed as `json`, `blob` and `form-data` depending on the `Content-Type` header sent by your function. Responses are parsed as `text` by default.
examples:
- id: basic-invocation
- name: Basic invocation.
+ name: Basic invocation
description:
isSpotlight: true
code: |
@@ -6953,7 +6970,7 @@ functions:
})
```
- id: error-handling
- name: Error handling.
+ name: Error handling
description: |
A `FunctionsHttpError` error is returned if your function throws an error, `FunctionsRelayError` if the Supabase Relay has an error processing your function and `FunctionsFetchError` if there is a network error in calling your function.
isSpotlight: true
@@ -6977,7 +6994,7 @@ functions:
}
```
- id: passing-custom-headers
- name: Passing custom headers.
+ name: Passing custom headers
description: |
You can pass custom headers to your function. Note: supabase-js automatically passes the `Authorization` header with the signed in user's JWT.
isSpotlight: true