Class: Supabase::Rails::User

Inherits:
Object
  • Object
show all
Defined in:
lib/supabase/rails/user.rb

Overview

Immutable value object representing the authenticated Supabase user.

Built from verified JWT claims by the middleware and exposed via ‘supabase_context.current_user`. When `config.supabase.user_model` is unset (default), this is also what populates `Current.user` for the Authentication concern (FR-W15). When the host app opts into a shadow AR `User` model (FR-W14), the concern substitutes the AR record for `Current.user` but `supabase_context.current_user` remains this value object.

All fields are read straight from the verified JWT payload — no extra ‘auth.get_user` round-trip. Use `supabase_context.supabase .auth.get_user` when the full `Supabase::Auth::Types::User` is required.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUser

Returns a new instance of User.



32
33
34
35
# File 'lib/supabase/rails/user.rb', line 32

def initialize(**)
  super
  freeze
end

Class Method Details

.from_claims(claims) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/supabase/rails/user.rb', line 20

def self.from_claims(claims)
  claims = {} unless claims.is_a?(Hash)
  new(
    id:            claims["sub"],
    email:         claims["email"],
    role:          claims["role"],
    app_metadata:  claims["app_metadata"],
    user_metadata: claims["user_metadata"],
    raw:           claims
  )
end