Supabase.GoTrue (supabase_gotrue v0.4.1)

This module provides the functionality to interact with the GoTrue API, allowing management of users, sessions, and authentication.

It also aims to provide integrations with Plug and Phoenix LiveView applications.

For detailed information about the GoTrue API, check the official documentation at https://supabase.io/docs/reference/javascript/auth-api

And also refer to functions and submodules documentation for more information.

Summary

Functions

Retrieves the auth module handle from the application configuration. Check https://hexdocs.pm/supabase_gotrue/readme.html#usage

Retrieves the server health from the GoTrue API.

Retrieves the server settings from the GoTrue API.

Get the user associated with the current session.

Exchanges a refresh token for a new session.

Resends a signup confirm email for the given email address.

Sends a recovery password email for the given email address.

Signs in a user anonymously.

Signs in a user with ID token.

Signs in a user with OAuth.

Signs in a user with OTP.

Signs in a user with email/phone and password.

Signs in a user with SSO.

Signs up a user with email/phone and password.

Updates the current logged in user.

Verifies an OTP code.

Functions

get_auth_module!()

Retrieves the auth module handle from the application configuration. Check https://hexdocs.pm/supabase_gotrue/readme.html#usage

get_server_health(client)

@spec get_server_health(Supabase.Client.t()) ::
  {:ok, Supabase.GoTrue.Schemas.ServerHealth.t()} | {:error, term()}

Retrieves the server health from the GoTrue API.

Parameters

  • client - The Supabase client to use for the request.

Examples

iex> Supabase.GoTrue.get_server_health(client)
{:ok, %Supabase.GoTrue.ServerHealth{}}

get_server_settings(client)

@spec get_server_settings(Supabase.Client.t()) ::
  {:ok, Supabase.GoTrue.Schemas.ServerSettings.t()} | {:error, term()}

Retrieves the server settings from the GoTrue API.

Parameters

  • client - The Supabase client to use for the request.

Examples

iex> Supabase.GoTrue.get_server_settings(client)
{:ok, %Supabase.GoTrue.ServerSettings{}}

get_user(client, session)

Get the user associated with the current session.

Parameters

Examples

iex> session = %Supabase.GoTrue.Session{access_token: "example_token"}
iex> Supabase.GoTrue.get_user(pid | client_name, session)
{:ok, %Supabase.GoTrue.User{}}

refresh_session(client, refresh_token)

@spec refresh_session(Supabase.Client.t(), refresh_token :: String.t()) ::
  {:ok, Supabase.GoTrue.Session.t()} | {:error, term()}

Exchanges a refresh token for a new session.

Parameters

  • client - The Supabase client to use for the request.
  • refresh_token - The refresh token to use for the request.

Examples

iex> Supabase.GoTrue.refresh_session(client, "refresh_token")
{:ok, %Supabase.GoTrue.Session{}}

resend(client, email, opts)

@spec resend(
  Supabase.Client.t(),
  String.t(),
  Supabase.GoTrue.Schemas.ResendParams.t()
) ::
  :ok | {:error, term()}

Resends a signup confirm email for the given email address.

Parameters

  • client - The Supabase client to use for the request.
  • email - A valid user email address to recover password
  • opts:
    • redirect_to: the url where the user should be redirected to reset their password
    • captcha_token

Examples

iex> Supabase.GoTrue.resend(client, "john@example.com", redirect_to: "http://localohst:4000/reset-pass") :ok

reset_password_for_email(client, email, opts)

@spec reset_password_for_email(Supabase.Client.t(), String.t(), opts) ::
  :ok | {:error, term()}
when opts:
       [{:redirect_to, String.t()}]
       | [{:captcha_token, String.t()}]
       | [redirect_to: String.t(), captcha_token: String.t()]

Sends a recovery password email for the given email address.

Parameters

  • client - The Supabase client to use for the request.
  • email - A valid user email address to recover password
  • opts:
    • redirect_to: the url where the user should be redirected to reset their password
    • captcha_token

Examples

iex> Supabase.GoTrue.reset_password_for_email(client, "john@example.com", redirect_to: "http://localohst:4000/reset-pass") :ok

sign_in_anonymously(client, opts \\ %{})

@spec sign_in_anonymously(Supabase.Client.t(), Enumerable.t()) ::
  {:ok, Supabase.GoTrue.Session.t()} | {:error, term()}

Signs in a user anonymously.

Parameters

Examples

iex> Supabase.GoTrue.sign_in_anonymously(pid | client_name, %{})
{:ok, %Supabase.GoTrue.Session{}}

sign_in_with_id_token(client, credentials)

Signs in a user with ID token.

Parameters

Examples

iex> credentials = %Supabase.GoTrue.SignInWithIdToken{}
iex> Supabase.GoTrue.sign_in_with_id_token(pid | client_name, credentials)
{:ok, %Supabase.GoTrue.Session{}}

sign_in_with_oauth(client, credentials)

Signs in a user with OAuth.

Parameters

Examples

iex> credentials = %Supabase.GoTrue.SignInWithOauth{}
iex> Supabase.GoTrue.sign_in_with_oauth(pid | client_name, credentials)
{:ok, atom, URI.t()}

sign_in_with_otp(client, credentials)

Signs in a user with OTP.

Parameters

Examples

iex> credentials = %Supabase.GoTrue.SignInWithOTP{}
iex> Supabase.GoTrue.sign_in_with_otp(pid | client_name, credentials)
:ok

sign_in_with_password(client, credentials)

Signs in a user with email/phone and password.

Parameters

Examples

iex> credentials = %Supabase.GoTrue.SignInWithPassword{}
iex> Supabase.GoTrue.sign_in_with_password(pid | client_name, credentials)
{:ok, %Supabase.GoTrue.Session{}}

sign_in_with_sso(client, credentials)

Signs in a user with SSO.

Parameters

Examples

iex> credentials = %Supabase.GoTrue.SignInWithSSO{}
iex> Supabase.GoTrue.sign_in_with_sso(pid | client_name, credentials)
{:ok, %Supabase.GoTrue.Session{}}

sign_up(client, credentials)

Signs up a user with email/phone and password.

Parameters

Examples

iex> credentials = %Supabase.GoTrue.SignUpWithPassword{}
iex> Supabase.GoTrue.sign_up(pid | client_name, credentials)
{:ok, %Supabase.GoTrue.User{}}

update_user(client, conn, attrs)

@spec update_user(Supabase.Client.t(), conn, Supabase.GoTrue.Schemas.UserParams.t()) ::
  {:ok, conn} | {:error, term()}
when conn: Plug.Conn.t() | Phoenix.LiveView.Socket.t()

Updates the current logged in user.

Parameters

Examples

iex> params = %{email: "another@example.com", password: "new-pass"}
iex> Supabase.GoTrue.update_user(client, conn, params)
{:ok, conn}

verify_otp(client, params)

Verifies an OTP code.

Parameters

Examples

iex> params = %Supabase.GoTrue.VerifyOTP{}
iex> Supabase.GoTrue.verify_otp(pid | client_name, params)
{:ok, %Supabase.GoTrue.Session{}}