supabase-rb-rb
Auth

Overview

Authentication, sessions, MFA, and admin user management.

The auth namespace wraps the GoTrue (Supabase Auth) API. Access it via supabase.auth after constructing a client. Methods use snake_case names, single-hash credentials, and keyword arguments for top-level options.

supabase = Supabase.create_client(
  supabase_url: ENV.fetch("SUPABASE_URL"),
  supabase_key: ENV.fetch("SUPABASE_ANON_KEY")
)

supabase.auth.sign_in_with_password(email: "ada@example.com", password: "secret")

Sign-in / sign-up

MethodDescription
sign_upCreate a new user with email/phone + password.
sign_in_with_passwordSign in with email/phone + password.
sign_in_with_otpSend a magic-link or SMS one-time password.
sign_in_with_oauthBuild a redirect URL for a third-party OAuth provider.
sign_in_with_id_tokenSign in with a provider-issued ID token (e.g. Google, Apple).
sign_in_with_ssoSign in via SAML SSO using domain or provider ID.
sign_in_anonymouslyCreate and sign in an anonymous user.
sign_outRevoke the current session and clear local storage.
verify_otpVerify a one-time password and produce a session.
resendResend a magic link, SMS OTP, or signup confirmation.

Sessions & user

MethodDescription
get_sessionReturn the current session, refreshing it if needed.
refresh_sessionForce-refresh the session using a refresh token.
set_sessionRestore a session from existing access + refresh tokens.
get_userFetch the user for the current (or a supplied) access token.
get_user_identitiesList the OAuth identities linked to the current user.
update_userUpdate the current user's email, password, or metadata.
get_claimsDecode and verify JWT claims for the current (or supplied) token.
reauthenticateTrigger a fresh nonce challenge for the current user.
reset_password_for_emailSend a password-reset email.
on_auth_state_changeSubscribe to SIGNED_IN / SIGNED_OUT / TOKEN_REFRESHED events.
exchange_code_for_sessionFinish a PKCE flow by exchanging the auth code for a session.
link_identityLink an OAuth identity to the current user.
unlink_identityUnlink an OAuth identity from the current user.

MFA (supabase.auth.mfa)

MethodDescription
mfa.enrollEnroll a new TOTP or phone factor.
mfa.challengeStart a verification challenge for a factor.
mfa.verifySubmit a code to satisfy a challenge.
mfa.challenge_and_verifyChallenge + verify in one call.
mfa.unenrollRemove an MFA factor.
mfa.list_factorsList the current user's verified factors.
mfa.get_authenticator_assurance_levelInspect AAL1/AAL2 state from the current JWT.

Admin (supabase.auth.admin)

The admin API requires a service_role key — see the admin overview for the warning and setup pattern.

MethodDescription
admin.create_userCreate a user directly, bypassing email/phone confirmation.
admin.list_usersList users with pagination.
admin.get_user_by_idFetch a single user by UUID.
admin.update_user_by_idUpdate any field on any user.
admin.delete_userHard- or soft-delete a user.
admin.invite_user_by_emailSend a signup invitation email.
admin.generate_linkGenerate magic-link / recovery / invite / signup URLs without sending the email.

Calling style

Ruby's hash-literal shorthand lets you write sign_in_with_password(email: "...", password: "...") directly. Sub-options stay nested under options: { ... } to match the wire payload.

On this page