supabase-rb-rb
Auth

Create a new user

Create a new user with email/phone + password.

Create a new user and (depending on your project's confirmation settings) sign them in. The credentials hash must include either email: or phone:, plus a password: — passwordless sign-in is handled by sign_in_with_otp.

On success, GoTrue returns the new user and — if email confirmation is disabled or the phone channel returns a session immediately — a session. On a project that requires email confirmation, session will be nil until the user clicks the confirmation link.

Signature

supabase.auth.sign_up(credentials)

credentials is a hash. You can pass it as a literal ({ email: "...", password: "..." }) or use Ruby's hash-literal shorthand (email: "...", password: "...") — both are equivalent.

Parameters

NameTypeRequiredDescription
emailStringOptionalUser email. Provide either email or phone, not both.
phoneStringOptionalUser phone number in E.164 format. Provide either email or phone, not both.
passwordStringRequiredThe new user password. Must satisfy your project password policy.
optionsHashOptionalNested options: data (Hash, user_metadata), captcha_token (String), email_redirect_to (String, URL to send in the confirmation email), redirect_to (String, alias of email_redirect_to), channel (String, sms or whatsapp for phone sign-up; defaults to sms).

Returns

Returns
Supabase::Auth::Types::AuthResponse

A Struct with :user and :session. When email confirmation is required, session is nil and the caller must wait for the user to click the confirmation link.

Example — email + password

response = supabase.auth.sign_up(
  email: "ada@example.com",
  password: "Lovelace-1815!"
)

response.user.email     # => "ada@example.com"
response.session&.access_token

Example — phone + password

response = supabase.auth.sign_up(
  phone: "+15555550123",
  password: "Lovelace-1815!",
  options: { channel: "sms" }
)

Example — with metadata, captcha, and redirect

response = supabase.auth.sign_up(
  email: "ada@example.com",
  password: "Lovelace-1815!",
  options: {
    data: { full_name: "Ada Lovelace", referrer: "blog" },
    captcha_token: "10000000-aaaa-bbbb-cccc-000000000001",
    email_redirect_to: "https://app.example.com/welcome"
  }
)

The one-of-email/phone rule and the "password required when email/phone is provided" rule both raise Supabase::Auth::Errors::AuthInvalidCredentialsError.

On this page