Supabase.GoTrue.Admin (supabase_gotrue v0.5.2)
View SourceAdmin module for GoTrue. This module provides functions to interact with the GoTrue admin API, like signing out a user, inviting a user, and generating a link.
You can find more information about the GoTrue admin API at https://supabase.io/docs/reference/javascript/auth-admin-api
Summary
Functions
Creates a user via the admin API.
Deletes a multi-factor authentication factor for a user.
Removes a specific authentication identity from a user.
Deletes a user via the admin API.
Generates an action link for various authentication purposes.
Gets a user by ID via the admin API.
Invites a user to join the application through email.
Lists all connected authentication identities for a specific user.
Lists users via the admin API with pagination support.
Signs out a user via the admin API.
Updates a user via the admin API.
Functions
Creates a user via the admin API.
Parameters
client
- TheSupabase
client to use for the request.attrs
- The attributes to use for the user:email
- User's email address (required if phone not provided)phone
- User's phone number (required if email not provided)password
- User's passwordemail_confirm
- Whether to mark the email as confirmedphone_confirm
- Whether to mark the phone as confirmedapp_metadata
- Application-specific metadata to store with the userban_duration
- Duration for which the user should be bannedrole
- User's rolenonce
- Custom nonce for the user
Returns
{:ok, user}
- Successfully created user{:error, error}
- Failed to create user
Examples
iex> attrs = %{email: "admin-created@example.com", password: "secure-password", email_confirm: true}
iex> Supabase.GoTrue.Admin.create_user(client, attrs)
{:ok, %Supabase.GoTrue.User{}}
Deletes a multi-factor authentication factor for a user.
Parameters
client
- TheSupabase
client to use for the request.user_id
- The ID of the user.factor_id
- The ID of the factor to delete.
Returns
:ok
- Successfully deleted the factor{:error, error}
- Failed to delete the factor
Examples
iex> Supabase.GoTrue.Admin.delete_factor(client, "d5bd2ef9-8df8-4e96-b592-35d120a8634c", "totp-factor-id")
:ok
Removes a specific authentication identity from a user.
Parameters
client
- TheSupabase
client to use for the request.user_id
- The ID of the user.identity_id
- The ID of the identity to delete.
Returns
:ok
- Successfully deleted the identity{:error, error}
- Failed to delete the identity
Examples
iex> Supabase.GoTrue.Admin.delete_identity(client, "d5bd2ef9-8df8-4e96-b592-35d120a8634c", "identity-id")
:ok
Deletes a user via the admin API.
Parameters
client
- TheSupabase
client to use for the request.user_id
- The ID of the user to delete.opts
- Controls deletion behavior.should_soft_delete
- When true, the user will be soft-deleted (default: false)
Returns
{:ok, user}
- Successfully deleted user (returns user data){:error, error}
- Failed to delete user
Examples
iex> Supabase.GoTrue.Admin.delete_user(client, "user_id")
{:ok, %Supabase.GoTrue.User{}}
# Soft delete a user
iex> Supabase.GoTrue.Admin.delete_user(client, "user_id", should_soft_delete: true)
{:ok, %Supabase.GoTrue.User{}}
Generates an action link for various authentication purposes.
Parameters
client
- TheSupabase
client to use for the request.attrs
- The attributes to use for the link:email
- The email for which to generate the link (required)type
- The type of link to generate (required). One of:signup
- Sign up link (requires password)invite
- Invitation linkmagicLink
- Magic link for passwordless authrecovery
- Password recovery linkemail_change_current
- Email change confirmation for current emailemail_change_new
- Email change confirmation for new email
password
- Required for signup linksredirect_to
- URL to redirect after action is completeddata
- Additional data to include
Returns
{:ok, properties}
- Successfully generated link with properties:action_link
- The link to send to the useremail_otp
- Email OTP if applicablehashed_token
- Hashed tokenredirect_to
- The redirect URLverification_type
- Type of verification
Examples
iex> attrs = %{email: "user@example.com", type: "recovery", redirect_to: "https://example.com/reset-password"}
iex> Supabase.GoTrue.Admin.generate_link(client, attrs)
{:ok, %{action_link: "https://auth.example.com/verify?...", ...}}
Gets a user by ID via the admin API.
Parameters
client
- TheSupabase
client to use for the request.user_id
- The ID of the user to get.
Returns
{:ok, user}
- Successfully retrieved user{:error, error}
- Failed to retrieve user
Examples
iex> Supabase.GoTrue.Admin.get_user_by_id(client, "d5bd2ef9-8df8-4e96-b592-35d120a8634c")
{:ok, %Supabase.GoTrue.User{}}
Invites a user to join the application through email.
Parameters
client
- TheSupabase
client to use for the request.email
- The email of the user to invite.options
- The options to use for the invite:data
- Additional data to include with the invitationredirect_to
- URL to redirect the user after accepting the invitation
Examples
iex> Supabase.GoTrue.Admin.invite_user_by_email(client, "john@example.com", %{redirect_to: "https://example.com/welcome"})
Lists all connected authentication identities for a specific user.
Parameters
client
- TheSupabase
client to use for the request.user_id
- The ID of the user.
Returns
{:ok, identities}
- Successfully retrieved the list of identities{:error, error}
- Failed to retrieve the identities
Examples
iex> Supabase.GoTrue.Admin.list_identities(client, "d5bd2ef9-8df8-4e96-b592-35d120a8634c")
{:ok, [%Supabase.GoTrue.User.Identity{provider: :google, ...}, ...]}
Lists users via the admin API with pagination support.
Parameters
client
- TheSupabase
client to use for the request.params
- The parameters to use for the list:page
- Page number for paginationper_page
- Number of users per page
Returns
{:ok, users, pagination}
- Successfully retrieved users with pagination infousers
- List of user objectspagination
- Pagination metadata including next_page, last_page, and total count
{:error, error}
- Failed to retrieve users
Examples
iex> Supabase.GoTrue.Admin.list_users(client, %{page: 1, per_page: 10})
{:ok, [%Supabase.GoTrue.User{}, ...], %{next_page: 2, last_page: 5, total: 42}}
Signs out a user via the admin API.
Parameters
client
- TheSupabase
client to use for the request.session
- The session to sign out, often retrieved from a sign in function.scope
- The scope to sign out the user from (atom)::global
- Sign out user from all devices and browser sessions:local
- Sign out user from current browser only:others
- Sign out user from all other devices except current browser
Returns
:ok
- Successfully signed out the user{:error, error}
- Failed to sign out the user
Examples
iex> session = %Session{access_token: "eyJhbGciO..."}
iex> Supabase.GoTrue.Admin.sign_out(client, session, :global)
:ok
Updates a user via the admin API.
Parameters
client
- TheSupabase
client to use for the request.user_id
- The ID of the user to update.attrs
- The attributes to update for the user:email
- User's email addressphone
- User's phone numberpassword
- User's passwordemail_confirm
- Whether to mark the email as confirmedphone_confirm
- Whether to mark the phone as confirmedapp_metadata
- Application-specific metadata to store with the userban_duration
- Duration for which the user should be bannedrole
- User's rolenonce
- Custom nonce for the user
Returns
{:ok, user}
- Successfully updated user{:error, error}
- Failed to update user
Examples
iex> attrs = %{role: "admin", app_metadata: %{plan: "premium"}}
iex> Supabase.GoTrue.Admin.update_user_by_id(client, "d5bd2ef9-8df8-4e96-b592-35d120a8634c", attrs)
{:ok, %Supabase.GoTrue.User{}}