GoTrueAdminApi
import { GoTrueAdminApi } from "https://esm.sh/@supabase/supabase-js@2.101.0/dist/index.d.mts";§Constructors
Creates an admin API client that can be used to manage users and OAuth clients.
import { GoTrueAdminApi } from '@supabase/auth-js'
const admin = new GoTrueAdminApi({
url: 'https://xyzcompany.supabase.co/auth/v1',
headers: { Authorization: `Bearer ${process.env.SUPABASE_SERVICE_ROLE_KEY}` },
})
§Properties
Creates a new custom OIDC/OAuth provider.
For OIDC providers, the server fetches and validates the OpenID Connect discovery document
from the issuer's well-known endpoint (or the provided discovery_url) at creation time.
This may return a validation error (error_code: "validation_failed") if the discovery
document is unreachable, not valid JSON, missing required fields, or if the issuer
in the document does not match the expected issuer.
This function should only be called on a server. Never expose your service_role key in the browser.
Creates a new OAuth client. Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
This function should only be called on a server. Never expose your service_role key in the browser.
Deletes a custom provider.
This function should only be called on a server. Never expose your service_role key in the browser.
Deletes an OAuth client. Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
This function should only be called on a server. Never expose your service_role key in the browser.
Gets details of a specific custom provider by identifier.
This function should only be called on a server. Never expose your service_role key in the browser.
Gets details of a specific OAuth client. Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
This function should only be called on a server. Never expose your service_role key in the browser.
Lists all custom providers with optional type filter.
This function should only be called on a server. Never expose your service_role key in the browser.
Lists all OAuth clients with optional pagination. Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
This function should only be called on a server. Never expose your service_role key in the browser.
Regenerates the secret for an OAuth client. Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
This function should only be called on a server. Never expose your service_role key in the browser.
Updates an existing custom provider.
When issuer or discovery_url is changed on an OIDC provider, the server re-fetches and
validates the discovery document before persisting. This may return a validation error
(error_code: "validation_failed") if the discovery document is unreachable, invalid, or
the issuer does not match.
This function should only be called on a server. Never expose your service_role key in the browser.
Updates an existing OAuth client. Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
This function should only be called on a server. Never expose your service_role key in the browser.
Contains all custom OIDC/OAuth provider administration methods.
Contains all MFA administration methods.
Contains all OAuth client administration methods. Only relevant when the OAuth 2.1 server is enabled in Supabase Auth.
§Methods
Creates a new user.
This function should only be called on a server. Never expose your service_role key in the browser.
With custom user metadata
const { data, error } = await supabase.auth.admin.createUser({
email: 'user@email.com',
password: 'password',
user_metadata: { name: 'Yoda' }
})
Auto-confirm the user's email
const { data, error } = await supabase.auth.admin.createUser({
email: 'user@email.com',
email_confirm: true
})
Auto-confirm the user's phone number
const { data, error } = await supabase.auth.admin.createUser({
phone: '1234567890',
phone_confirm: true
})
Delete a user. Requires a service_role key.
The user id you want to remove.
If true, then the user will be soft-deleted from the auth schema. Soft deletion allows user identification from the hashed user ID but is not reversible. Defaults to false for backward compatibility.
This function should only be called on a server. Never expose your service_role key in the browser.
Removes a user
const { data, error } = await supabase.auth.admin.deleteUser(
'715ed5db-f090-4b8c-a067-640ecee36aa0'
)
Generates email links and OTPs to be sent via a custom email provider.
The user's email.
User password. For signup only.
Optional user metadata. For signup only.
The redirect url which should be appended to the generated link
Generate a signup link
const { data, error } = await supabase.auth.admin.generateLink({
type: 'signup',
email: 'email@example.com',
password: 'secret'
})
Generate an invite link
const { data, error } = await supabase.auth.admin.generateLink({
type: 'invite',
email: 'email@example.com'
})
Generate a magic link
const { data, error } = await supabase.auth.admin.generateLink({
type: 'magiclink',
email: 'email@example.com'
})
Generate a recovery link
const { data, error } = await supabase.auth.admin.generateLink({
type: 'recovery',
email: 'email@example.com'
})
Generate links to change current email address
// generate an email change link to be sent to the current email address
const { data, error } = await supabase.auth.admin.generateLink({
type: 'email_change_current',
email: 'current.email@example.com',
newEmail: 'new.email@example.com'
})
// generate an email change link to be sent to the new email address
const { data, error } = await supabase.auth.admin.generateLink({
type: 'email_change_new',
email: 'current.email@example.com',
newEmail: 'new.email@example.com'
})
Get user by id.
The user's unique identifier
This function should only be called on a server. Never expose your service_role key in the browser.
Fetch the user object using the access_token jwt
const { data, error } = await supabase.auth.admin.getUserById(1)
Sends an invite link to an email address.
The email address of the user.
Additional options to be included when inviting.
Invite a user
const { data, error } = await supabase.auth.admin.inviteUserByEmail('email@example.com')
Get a list of users.
This function should only be called on a server. Never expose your service_role key in the browser.
An object which supports page and perPage as numbers, to alter the paginated results.
Get a page of users
const { data: { users }, error } = await supabase.auth.admin.listUsers()
Paginated list of users
const { data: { users }, error } = await supabase.auth.admin.listUsers({
page: 1,
perPage: 1000
})
Updates the user data. Changes are applied directly without confirmation flows.
The user's unique identifier
The data you want to update.
This function should only be called on a server. Never expose your service_role key in the browser.
// Server-side (Edge Function)
const { data, error } = await supabase.auth.admin.updateUserById(
userId,
{ user_metadata: { preferences: { theme: 'dark' } } }
)
// Client-side (to sync the changes)
const { data, error } = await supabase.auth.refreshSession()
// onAuthStateChange listeners will now be notified with updated user
Updates a user's email
const { data: user, error } = await supabase.auth.admin.updateUserById(
'11111111-1111-1111-1111-111111111111',
{ email: 'new@email.com' }
)
Updates a user's password
const { data: user, error } = await supabase.auth.admin.updateUserById(
'6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4',
{ password: 'new_password' }
)
Updates a user's metadata
const { data: user, error } = await supabase.auth.admin.updateUserById(
'6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4',
{ user_metadata: { hello: 'world' } }
)
Updates a user's app_metadata
const { data: user, error } = await supabase.auth.admin.updateUserById(
'6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4',
{ app_metadata: { plan: 'trial' } }
)
Confirms a user's email address
const { data: user, error } = await supabase.auth.admin.updateUserById(
'6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4',
{ email_confirm: true }
)
Confirms a user's phone number
const { data: user, error } = await supabase.auth.admin.updateUserById(
'6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4',
{ phone_confirm: true }
)
Ban a user for 100 years
const { data: user, error } = await supabase.auth.admin.updateUserById(
'6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4',
{ ban_duration: '876000h' }
)