Skip to content

Commit 599e025

Browse files
authored
Merge branch 'main' into update/elixir-deps
2 parents 8b33431 + 9c4af52 commit 599e025

File tree

12 files changed

+142
-17
lines changed

12 files changed

+142
-17
lines changed

lib/supabase.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,9 @@ defmodule Supabase do
165165
defmacro __using__(which) when is_atom(which) do
166166
apply(__MODULE__, which, [])
167167
end
168+
169+
@doc "Returns the configured JSON encoding library for Supabase libraries."
170+
def json_library do
171+
Application.get_env(:supabase, :json_library, Jason)
172+
end
168173
end

lib/supabase/fetcher.ex

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ defmodule Supabase.Fetcher do
137137
alias Supabase.Fetcher.Response
138138
alias Supabase.Fetcher.ResponseAdapter
139139

140+
require Logger
141+
140142
@behaviour Supabase.Fetcher.Behaviour
141143

142144
@typedoc "Generic typespec to define possible response values, adapt to each client"
@@ -267,7 +269,14 @@ defmodule Supabase.Fetcher do
267269
defp handle_response({:error, %Error{} = err}, %Request{} = builder) do
268270
metadata = Error.make_default_http_metadata(builder)
269271
metadata = Map.merge(metadata, err.metadata)
270-
{:error, %{err | metadata: metadata}}
272+
273+
{:error,
274+
%{err | metadata: metadata}
275+
|> tap(
276+
&Logger.error("""
277+
[#{__MODULE__}]: Error response while processing request. #{inspect(&1)}
278+
""")
279+
)}
271280
end
272281

273282
defp handle_response({:error, err}, %Request{} = builder) do
@@ -278,6 +287,11 @@ defmodule Supabase.Fetcher do
278287
code: :unexpected,
279288
service: builder.service,
280289
metadata: Map.put(metadata, :raw_error, err)
290+
)
291+
|> tap(
292+
&Logger.debug("""
293+
[#{__MODULE__}]: Unexpected error while processing request. #{inspect(&1)}
294+
""")
281295
)}
282296
end
283297

@@ -292,6 +306,11 @@ defmodule Supabase.Fetcher do
292306
message: message,
293307
service: builder.service,
294308
metadata: %{stacktrace: stacktrace, exception: exception}
309+
)
310+
|> tap(
311+
&Logger.error("""
312+
[#{__MODULE__}]: Exception raised while processing request. #{inspect(&1)}
313+
""")
295314
)}
296315
end
297316

lib/supabase/fetcher/body_decoder.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ defmodule Supabase.Fetcher.JSONDecoder do
3535
@impl true
3636
def decode(%Response{body: body}, opts \\ []) do
3737
keys = Keyword.get(opts, :keys, :strings)
38-
Jason.decode(body, keys: keys)
38+
Supabase.json_library().decode(body, keys: keys)
3939
end
4040
end

lib/supabase/fetcher/request.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,15 @@ defmodule Supabase.Fetcher.Request do
196196

197197
@doc """
198198
Defines the request body to be sent, it can be a map, that will be encoded
199-
with `Jason.encode_to_iodata!/1`, any `iodata` or a stream body in the pattern of `{:stream, Enumerable.t}`, although you will problably prefer to use the `upload/2`
199+
with `encode_to_iodata!/1`, any `iodata` or a stream body in the pattern of `{:stream, Enumerable.t}`, although you will problably prefer to use the `upload/2`
200200
function of this module to hadle body stream since it will handle file management, content headers and so on.
201201
"""
202202
@impl true
203203
def with_body(builder, body \\ nil)
204204

205205
def with_body(%__MODULE__{} = builder, %{} = body) do
206-
%{builder | body: Jason.encode_to_iodata!(body)}
206+
json_library = Supabase.json_library()
207+
%{builder | body: json_library.encode_to_iodata!(body)}
207208
end
208209

209210
def with_body(%__MODULE__{} = builder, body) do

lib/supabase/fetcher/request/behaviour.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule Supabase.Fetcher.Request.Behaviour do
1414
@callback with_http_client(Request.t(), adapter :: module) :: Request.t()
1515
@callback with_query(Request.t(), query :: Enumerable.t()) :: Request.t()
1616
@callback with_body(Request.t(), body) :: Request.t()
17-
when body: Jason.Encoder.t() | {:stream, Enumerable.t()} | nil
17+
when body: term | {:stream, Enumerable.t()} | nil
1818
@callback with_headers(Request.t(), headers) :: Request.t()
1919
when headers: Supabase.Fetcher.headers()
2020
@callback with_body_decoder(Request.t(), decoder, decoder_opts) :: Request.t()

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ defmodule Supabase.MixProject do
3333
[
3434
{:mime, "~> 2.0"},
3535
{:finch, "~> 0.18"},
36-
{:jason, "~> 1.4"},
3736
{:ecto, "~> 3.10"},
37+
{:jason, "~> 1.4", optional: true},
3838
{:mox, "~> 1.2", only: :test},
3939
{:ex_doc, ">= 0.0.0", only: [:dev, :test], runtime: false},
4040
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},

supabase/config.toml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ enabled = true
5050
sql_paths = ['./seed.sql']
5151

5252
[realtime]
53-
enabled = false
53+
enabled = true
5454
# Bind realtime via either IPv4 or IPv6. (default: IPv4)
5555
# ip_version = "IPv6"
5656
# The maximum length in bytes of HTTP request headers. (default: 4096)
@@ -68,7 +68,7 @@ openai_api_key = "env(OPENAI_API_KEY)"
6868
# Email testing server. Emails sent with the local dev setup are not actually sent - rather, they
6969
# are monitored, and you can view the emails that would have been sent from the web interface.
7070
[inbucket]
71-
enabled = false
71+
enabled = true
7272
# Port to use for the email testing server web interface.
7373
port = 54324
7474
# Uncomment to expose additional ports for testing user applications that send emails.
@@ -126,9 +126,9 @@ enable_signup = true
126126
# addresses. If disabled, only the new email is required to confirm.
127127
double_confirm_changes = false
128128
# If enabled, users need to confirm their email address before signing in.
129-
enable_confirmations = false
129+
enable_confirmations = true
130130
# If enabled, users will need to reauthenticate or have logged in recently to change their password.
131-
secure_password_change = false
131+
secure_password_change = true
132132
# Controls the minimum amount of time that must pass before sending another signup confirmation or password reset email.
133133
max_frequency = "1s"
134134
# Number of characters used in the email OTP.
@@ -146,10 +146,21 @@ otp_expiry = 3600
146146
# admin_email = "[email protected]"
147147
# sender_name = "Admin"
148148

149-
# Uncomment to customize email template
150-
# [auth.email.template.invite]
151-
# subject = "You have been invited"
152-
# content_path = "./supabase/templates/invite.html"
149+
[auth.email.template.invite]
150+
subject = "You have been invited"
151+
content_path = "./supabase/templates/invite_user.html"
152+
153+
[auth.email.template.recovery]
154+
subject = "Password recovery"
155+
content_path = "./supabase/templates/reset_password.html"
156+
157+
[auth.email.template.confirmation]
158+
subject = "Signup confirmation"
159+
content_path = "./supabase/templates/confirm_signup.html"
160+
161+
[auth.email.template.magicLink]
162+
subject = "Your magic Link"
163+
content_path = "./supabase/templates/magic_link_otp.html"
153164

154165
[auth.sms]
155166
# Allow/disallow new user signups via SMS to your project.
@@ -217,10 +228,10 @@ client_id = "client-id-123"
217228
secret = "secret-123456"
218229

219230
[auth.external.apple]
220-
enabled = false
221-
client_id = ""
231+
enabled = true
232+
client_id = "client-123"
222233
# DO NOT commit your OAuth provider secret to git. Use environment variable substitution instead:
223-
secret = "env(SUPABASE_AUTH_EXTERNAL_APPLE_SECRET)"
234+
secret = "secret-123"
224235
# Overrides the default auth redirectUrl.
225236
redirect_uri = ""
226237
# Overrides the default auth provider URL. Used to support self-hosted gitlab, single-tenant Azure,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Password Recovery</title>
8+
</head>
9+
10+
<body>
11+
<main>
12+
<div class="email-content">
13+
<h2>Hello!</h2>
14+
<p>Check the link below:</p>
15+
<a href="{{ .SiteURL }}?token_hash={{ .TokenHash }}&type=signup">
16+
{{ .SiteURL }}?token_hash={{ .TokenHash }}&type=signup
17+
</a>
18+
</div>
19+
</main>
20+
</body>
21+
22+
</html>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Invitation</title>
8+
</head>
9+
10+
<body>
11+
<main>
12+
<div>
13+
<h2>Hello!</h2>
14+
<p>Check the link below</p>
15+
<a href="{{ .ConfirmationURL }}">{{ .ConfirmationURL }}</a>
16+
</div>
17+
</main>
18+
</body>
19+
20+
</html>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Magic Link</title>
8+
</head>
9+
10+
<body>
11+
<main>
12+
<div class="email-content">
13+
<h2>Hello!</h2>
14+
<p>Check the link below</p>
15+
<a href="{{ .SiteURL }}?token_hash={{ .TokenHash }}&type=magiclink">
16+
{{ .SiteURL }}?token_hash={{ .TokenHash }}&type=magiclink
17+
</a>
18+
<p>Or use the following token code {{ .Token }}</p>
19+
</div>
20+
</main>
21+
</body>
22+
23+
</html>

0 commit comments

Comments
 (0)