Skip to content

Commit

Permalink
feat: resend signup email
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedsoupe committed May 18, 2024
1 parent 4000c33 commit 3b6b558
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/supabase/go_true.ex
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,28 @@ defmodule Supabase.GoTrue do
end
end

@doc """
Resends a signuo 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, "[email protected]", redirect_to: "http://localohst:4000/reset-pass")
:ok
"""
@spec resend(Client.client(), String.t, opts) :: :ok | {:error, term}
when opts: [redirect_to: String.t] | [captcha_token: String.t] | [redirect_to: String.t, captcha_token: String.t]
def resend(client, email, opts) when is_client(client) do
with {:ok, client} <- Client.retrieve_client(client) do
UserHandler.resend_signup(client, email, Map.new(opts))
end
end

@doc """
Updates the current logged in user.
Expand Down
17 changes: 17 additions & 0 deletions lib/supabase/go_true/user_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule Supabase.GoTrue.UserHandler do
@otp_uri "/otp"
@verify_otp_uri "/verify"
@reset_pass_uri "/recover"
@resend_signup_uri "/resend"

def get_user(%Client{} = client, access_token) do
headers = Fetcher.apply_client_headers(client, access_token)
Expand Down Expand Up @@ -170,6 +171,22 @@ defmodule Supabase.GoTrue.UserHandler do
end
end

def resend_signup(%Client{} = client, email, %{} = opts) do
body = %{
email: email,
type: opts.type,
go_true_meta_security: %{captcha_token: opts[:captcha_token]}
}

headers = Fetcher.apply_client_headers(client)
endpoint = Client.retrieve_auth_url(client, @resend_signup_uri)
endpoint = append_query(endpoint, %{redirect_to: opts[:redirect_to]})

with {:ok, _} <- Fetcher.post(endpoint, body, headers) |> IO.inspect() do
:ok
end
end

def update_user(%Client{} = client, conn, %{} = params)
when client.auth.flow_type == :pkce do
{challenge, method} = generate_pkce()
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule SupabaseAuth.MixProject do
use Mix.Project

@version "0.3.5"
@version "0.3.6"
@source_url "https://github.com/zoedsoupe/gotrue-ex"

def project do
Expand Down

0 comments on commit 3b6b558

Please sign in to comment.