Skip to content

Commit b7bfe78

Browse files
committed
feat: introduce examples sample apps (readme)
1 parent 59ac270 commit b7bfe78

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

README.md

+16-22
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,29 @@ Where the magic starts!
77
88
## Getting Started
99

10-
### Installation
10+
### Examples
1111

12-
To install the base SDK:
12+
This repository contains a few examples with sample apps to help you get started and showcase each usage of the client implementations:
1313

14-
```elixir
15-
def deps do
16-
[
17-
{:supabase_potion, "~> 0.5"}
18-
]
19-
end
20-
```
14+
#### Gotrue/Auth examples
2115

22-
### General installation
16+
- [Plug based auth](https://github.com/zoedsoupe/supabase-ex/tree/main/examples/auth/plug)
17+
- [Phoenix LiveView based auth](https://github.com/zoedsoupe/supabase-ex/tree/main/examples/auth/phoenix_live_view)
18+
- [User management](https://github.com/zoedsoupe/supabase-ex/tree/main/examples/auth/user_management)
2319

24-
This library per si is the base foundation to user Supabase services from Elixir, so to integrate with specific services you need to add each client library you want to use.
20+
#### Storage examples
2521

26-
Available client services are:
27-
- [PostgREST](https://github.com/zoedsoupe/postgres-ex)
28-
- [Storage](https://github.com/zoedsoupe/storage-ex)
29-
- [Auth/GoTrue](https://github.com/zoedsoupe/gotrue-ex)
22+
- [Plug based upload](https://github.com/zoedsoupe/supabase-ex/tree/main/examples/storage/plug)
23+
- [Phoenix LiveView upload](https://github.com/zoedsoupe/supabase-ex/tree/main/examples/storage/phoenix_live_view)
3024

31-
So if you wanna use the Storage and Auth/GoTrue services, your `mix.exs` should look like that:
25+
### Installation
26+
27+
To install the base SDK:
3228

3329
```elixir
3430
def deps do
3531
[
36-
{:supabase_potion, "~> 0.5"}, # base SDK
37-
{:supabase_storage, "~> 0.3"}, # storage integration
38-
{:supabase_gotrue, "~> 0.3"}, # auth integration
32+
{:supabase_potion, "~> 0.5"}
3933
]
4034
end
4135
```
@@ -54,7 +48,7 @@ So if you wanna use the Storage and Auth/GoTrue services, your `mix.exs` should
5448
```elixir
5549
def deps do
5650
[
57-
{:supabase_potion, "~> 0.4"}, # base SDK
51+
{:supabase_potion, "~> 0.5"}, # base SDK
5852
{:supabase_storage, "~> 0.3"}, # storage integration
5953
{:supabase_gotrue, "~> 0.3"}, # auth integration
6054
]
@@ -149,7 +143,7 @@ So, to define a self managed client, you need to define a module that will hold
149143

150144
```elixir
151145
defmodule MyApp.Supabase.Client do
152-
use Supabase.Client
146+
use Supabase.Client, otp_app: :my_app
153147
end
154148
```
155149

@@ -158,7 +152,7 @@ For that to work, you also need to configure the client in your `config.exs`:
158152
```elixir
159153
import Config
160154

161-
config :supabase_potion, MyApp.Supabase.Client,
155+
config :my_app, MyApp.Supabase.Client,
162156
base_url: "https://<supabase-url>", # required
163157
api_key: "<supabase-api-key>", # required
164158
conn: %{access_token: "<supabase-token>"}, # optional

lib/supabase/client.ex

+13-11
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ defmodule Supabase.Client do
1919
To achieve this you can use the `Supabase.Client` module in your module:
2020
2121
defmodule MyApp.Supabase.Client do
22-
use Supabase.Client
22+
use Supabase.Client, otp_app: :my_app
2323
end
2424
2525
This will automatically start an Agent process to manage the connection options for you. But for that to work, you need to configure your defined Supabase client in your `config.exs`:
2626
27-
config :supabase_potion, MyApp.Supabase.Client,
27+
config :my_app, MyApp.Supabase.Client,
2828
base_url: "https://<app-name>.supabase.co",
2929
api_key: "<supabase-api-key>",
3030
conn: %{access_token: "<supabase-access-token>"}, # optional
@@ -107,7 +107,7 @@ defmodule Supabase.Client do
107107
auth: Auth.params()
108108
}
109109

110-
defmacro __using__(_) do
110+
defmacro __using__(otp_app: otp_app) do
111111
quote do
112112
use Agent
113113

@@ -123,6 +123,8 @@ defmodule Supabase.Client do
123123

124124
@behaviour Supabase.Client.Behaviour
125125

126+
@otp_app unquote(otp_app)
127+
126128
@doc """
127129
Start an Agent process to manage the Supabase client instance.
128130
@@ -131,12 +133,12 @@ defmodule Supabase.Client do
131133
First, define your client module and use the `Supabase.Client` module:
132134
133135
defmodule MyApp.Supabase.Client do
134-
use Supabase.Client
136+
use Supabase.Client, otp_app: :my_app
135137
end
136138
137139
Note that you need to configure it with your Supabase project details. You can do this by setting the `base_url` and `api_key` in your `config.exs` file:
138140
139-
config :supabase_potion, MyApp.Supabase.Client,
141+
config :#{@otp_app}, MyApp.Supabase.Client,
140142
base_url: "https://<app-name>.supabase.co",
141143
api_key: "<supabase-api-key>",
142144
conn: %{access_token: "<supabase-access-token>"}, # optional
@@ -160,10 +162,10 @@ defmodule Supabase.Client do
160162
def start_link(opts \\ [])
161163

162164
def start_link(opts) when is_list(opts) and opts == [] do
163-
config = Application.get_env(:supabase_potion, __MODULE__)
165+
config = Application.get_env(@otp_app, __MODULE__)
164166

165167
if is_nil(config) do
166-
raise MissingSupabaseConfig, key: :config, client: __MODULE__
168+
raise MissingSupabaseConfig, key: :config, client: __MODULE__, otp_app: @otp_app
167169
end
168170

169171
base_url = Keyword.get(config, :base_url)
@@ -172,11 +174,11 @@ defmodule Supabase.Client do
172174
params = Map.new(config)
173175

174176
if is_nil(base_url) do
175-
raise MissingSupabaseConfig, key: :url, client: __MODULE__
177+
raise MissingSupabaseConfig, key: :url, client: __MODULE__, otp_app: @otp_app
176178
end
177179

178180
if is_nil(api_key) do
179-
raise MissingSupabaseConfig, key: :key, client: __MODULE__
181+
raise MissingSupabaseConfig, key: :key, client: __MODULE__, otp_app: @otp_app
180182
end
181183

182184
Agent.start_link(fn -> Supabase.init_client!(base_url, api_key, params) end, name: name)
@@ -187,11 +189,11 @@ defmodule Supabase.Client do
187189
api_key = Keyword.get(opts, :api_key)
188190

189191
if is_nil(base_url) do
190-
raise MissingSupabaseConfig, key: :url, client: __MODULE__
192+
raise MissingSupabaseConfig, key: :url, client: __MODULE__, otp_app: @otp_app
191193
end
192194

193195
if is_nil(api_key) do
194-
raise MissingSupabaseConfig, key: :key, client: __MODULE__
196+
raise MissingSupabaseConfig, key: :key, client: __MODULE__, otp_app: @otp_app
195197
end
196198

197199
name = Keyword.get(opts, :name, __MODULE__)

0 commit comments

Comments
 (0)