Supabase. Client
(supabase_potion v1.0.0)
Copy Markdown
A client for interacting with Supabase. This module is responsible for managing the connection options for your Supabase project.
Usage
There are two ways to create a Supabase client:
1. Module-based Client (Recommended)
Define a client module using the macro (similar to Ecto Repo). This approach reads configuration from your application config and builds a fresh client struct on each call:
# lib/my_app/supabase.ex
defmodule MyApp.Supabase do
use Supabase.Client, otp_app: :my_app
end
# config/config.exs
config :my_app, MyApp.Supabase,
base_url: "https://<app-name>.supabase.io",
api_key: "<supabase-api-key>",
db: [schema: "public"],
auth: [flow_type: :pkce]
# Usage
iex> client = MyApp.Supabase.get_client!()
iex> %Supabase.Client{}2. Direct Initialization
Alternatively, create a client directly using Supabase.init_client/3:
iex> base_url = "https://<app-name>.supabase.io"
iex> api_key = "<supabase-api-key>"
iex> Supabase.init_client(base_url, api_key, %{})
{:ok, %Supabase.Client{}}For more information on how to configure your Supabase Client with additional
options, please refer to the Supabase.Client.t() typespec.
Client Structure
%Supabase.Client{
base_url: "https://<app-name>.supabase.io",
api_key: "<supabase-api-key>",
access_token: "<supabase-access-token>",
db: %Supabase.Client.Db{
schema: "public"
},
global: %Supabase.Client.Global{
headers: %{}
},
auth: %Supabase.Client.Auth{
auto_refresh_token: true,
debug: false,
detect_session_in_url: true,
flow_type: :implicit,
persist_session: true,
storage_key: "sb-<host>-auth-token"
},
storage: %Supabase.Client.Storage{
use_new_hostname: false
}
}
Summary
Types
The type for the available additional options that can be passed
to Supabase.init_client/3 to configure the Supabase client.
The type of the Supabase.Client that will be returned from Supabase.init_client/3.
Functions
Helper function to swap the current acccess token being used in the Supabase client instance.
Types
@type options() :: %{ optional(:db) => Supabase.Client.Db.params(), optional(:global) => Supabase.Client.Global.params(), optional(:auth) => Supabase.Client.Auth.params(), optional(:storage) => Supabase.Client.Storage.params() }
The type for the available additional options that can be passed
to Supabase.init_client/3 to configure the Supabase client.
@type t() :: %Supabase.Client{ access_token: String.t(), api_key: String.t(), auth: Supabase.Client.Auth.t(), auth_url: String.t(), base_url: String.t(), database_url: String.t(), db: Supabase.Client.Db.t(), functions_url: String.t(), global: Supabase.Client.Global.t(), realtime_url: String.t(), storage: Supabase.Client.Storage.t(), storage_url: String.t() }
The type of the Supabase.Client that will be returned from Supabase.init_client/3.
Source
Functions
@spec changeset(attrs :: map()) :: Ecto.Changeset.t()
Helper function to swap the current acccess token being used in the Supabase client instance.