supabase-rb-rb
Auth

Create an anonymous user

Create and sign in an anonymous user.

Create a new anonymous user and start a session for them. Anonymous users have a real user.id (and can be upgraded later by update_user — adding an email/password — or by link_identity — adding an OAuth identity), so subsequent calls to auth.get_user work as for any other user.

Anonymous sign-in must be enabled in the Supabase dashboard under Authentication → Providers → Anonymous Sign-Ins for the request to succeed.

Signature

supabase.auth.sign_in_anonymously(credentials = nil)

credentials is optional. Pass it as a hash if you want to attach metadata or a captcha token.

Parameters

NameTypeRequiredDescription
credentialsHashOptionalOptional credentials hash. May contain an options sub-hash.
optionsHashOptionalNested under credentials. Keys: data (Hash, written to user_metadata on the new user), captcha_token (String).

Returns

Returns
Supabase::Auth::Types::AuthResponse

A Struct with :user and :session. On success both are populated — the anonymous user is signed in immediately.

Example — minimal

response = supabase.auth.sign_in_anonymously

response.user.id              # => "..."
response.user.email           # => nil (anonymous)
response.session.access_token # => "..."

Example — with metadata

response = supabase.auth.sign_in_anonymously(
  options: { data: { display_name: "Guest 42", referrer: "landing" } }
)

response.user.user_metadata["display_name"] # => "Guest 42"

Example — upgrade to a real account later

guest = supabase.auth.sign_in_anonymously

# Later, attach an email + password to the same user.id:
supabase.auth.update_user(email: "ada@example.com", password: "Lovelace-1815!")

On this page