Supabase.GoTrue.User (supabase_gotrue v0.5.2)
View SourceRepresents a user profile in the Supabase authentication system.
This schema contains all the user information stored in the GoTrue service, including
authentication details, profile data, and linked identities. The User struct is typically
accessed through Supabase.GoTrue.get_user/2
after a successful authentication.
Important Fields
id
- Unique identifier (UUID) for the useremail
- User's email address (if applicable)phone
- User's phone number (if applicable)user_metadata
- Custom user attributes, editable by the userapp_metadata
- Application-controlled attributes, not editable by the usercreated_at
- Timestamp when the user was createdlast_sign_in_at
- Timestamp of the user's most recent sign-inconfirmed_at
- Timestamp when the user was confirmed (email verification)factors
- Multi-factor authentication methods associated with the useridentities
- External identity providers linked to this user (GitHub, Google, etc.)is_anonymous
- Set to true if user is authenticated as anonymous
Confirmation Status
A user's verification status for email and phone can be determined using the following fields:
email_confirmed_at
- Non-nil when email is verifiedphone_confirmed_at
- Non-nil when phone is verified
Example Usage
# Retrieve user details from a session
{:ok, user} = Supabase.GoTrue.get_user(client, session)
# Check if email is verified
email_verified = user.email_confirmed_at != nil
# Access custom user metadata
profile_pic = user.user_metadata["avatar_url"]
Related Schemas
Supabase.GoTrue.User.Factor
- MFA factors associated with the userSupabase.GoTrue.User.Identity
- External identity providers linked to the user
Summary
Functions
Parses and validates a map of user attributes into a User struct.
Parses a list of user attribute maps into a list of User structs.
Types
@type t() :: %Supabase.GoTrue.User{ action_link: String.t() | nil, app_metadata: map(), aud: String.t(), confirmation_sent_at: NaiveDateTime.t() | nil, confirmed_at: NaiveDateTime.t() | nil, created_at: NaiveDateTime.t(), email: String.t() | nil, email_change_sent_at: NaiveDateTime.t() | nil, email_confirmed_at: NaiveDateTime.t() | nil, encrypted_password: term(), factors: [Supabase.GoTrue.User.Factor] | nil, id: Ecto.UUID.t(), identities: [Supabase.GoTrue.User.Identity] | nil, invited_at: NaiveDateTime.t() | nil, is_anonymous: boolean() | nil, last_sign_in_at: NaiveDateTime.t() | nil, new_email: String.t() | nil, new_phone: String.t() | nil, phone: String.t() | nil, phone_confirmed_at: NaiveDateTime.t() | nil, recovery_sent_at: NaiveDateTime.t() | nil, role: String.t() | nil, updated_at: NaiveDateTime.t() | nil, user_metadata: map() }
Functions
Parses and validates a map of user attributes into a User struct.
This function validates that all required fields are present and correctly formatted, returning either a valid User struct or a changeset with validation errors.
Parameters
attrs
- Map containing user attributes returned from the GoTrue API
Returns
{:ok, user}
- Successfully parsed user{:error, changeset}
- Failed validation with error details
Examples
iex> attrs = %{
...> "id" => "550e8400-e29b-41d4-a716-446655440000",
...> "email" => "user@example.com",
...> "app_metadata" => %{},
...> "user_metadata" => %{"name" => "Test User"},
...> "aud" => "authenticated",
...> "created_at" => "2023-01-01T00:00:00Z"
...> }
iex> {:ok, user} = Supabase.GoTrue.User.parse(attrs)
iex> user.email
"user@example.com"
Parses a list of user attribute maps into a list of User structs.
This function attempts to validate and parse each map in the provided list. If all validations succeed, it returns a list of User structs. If any validation fails, it returns the first error encountered.
Parameters
list_attrs
- List of maps containing user attributes
Returns
{:ok, [user, ...]}
- Successfully parsed list of users{:error, changeset}
- First validation error encountered
Examples
iex> attrs_list = [
...> %{"id" => "user1", "app_metadata" => %{}, "aud" => "auth", "created_at" => "2023-01-01T00:00:00Z"},
...> %{"id" => "user2", "app_metadata" => %{}, "aud" => "auth", "created_at" => "2023-01-01T00:00:00Z"}
...> ]
iex> {:ok, users} = Supabase.GoTrue.User.parse_list(attrs_list)
iex> length(users)
2