Supabase.GoTrue.Session (supabase_gotrue v0.5.2)

View Source

Represents an authenticated session with Supabase's GoTrue service.

A session contains the tokens and metadata necessary for authenticating subsequent API requests. It is returned after a successful sign-in or sign-up operation and can be refreshed using Supabase.GoTrue.refresh_session/2.

Fields

  • access_token - JWT token used for API authorization (required)
  • refresh_token - Token used to obtain a new access token when it expires (required)
  • expires_in - Number of seconds until the access token expires (required)
  • expires_at - Unix timestamp (in seconds) when the token expires
  • token_type - Type of token, usually "bearer" (required)
  • provider_token - OAuth provider-specific token (if applicable)
  • provider_refresh_token - OAuth provider-specific refresh token (if applicable)
  • user - The authenticated user's profile information (Supabase.GoTrue.User)

Usage

# Store the session securely after sign-in
{:ok, session} = Supabase.GoTrue.sign_in_with_password(client, credentials)

# Use the session for authenticated requests
{:ok, user} = Supabase.GoTrue.get_user(client, session)

# Refresh the session before it expires
{:ok, refreshed_session} = Supabase.GoTrue.refresh_session(client, session.refresh_token)

Security Notes

  • The access_token contains sensitive information and should be secured appropriately
  • Sessions should be refreshed before they expire to maintain authentication
  • For web applications, it's recommended to store session tokens in HTTP-only cookies

Summary

Types

t()

@type t() :: %Supabase.GoTrue.Session{
  access_token: String.t(),
  expires_at: integer() | nil,
  expires_in: integer(),
  provider_refresh_token: String.t() | nil,
  provider_token: String.t() | nil,
  refresh_token: String.t(),
  token_type: String.t(),
  user: Supabase.GoTrue.User.t()
}

Functions

parse(attrs)

@spec parse(map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}