diff --git a/lib/supabase/go_true.ex b/lib/supabase/go_true.ex index 5492a64..f7165c8 100644 --- a/lib/supabase/go_true.ex +++ b/lib/supabase/go_true.ex @@ -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, "john@example.com", 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. diff --git a/lib/supabase/go_true/user_handler.ex b/lib/supabase/go_true/user_handler.ex index 20f6f5d..dbc009b 100644 --- a/lib/supabase/go_true/user_handler.ex +++ b/lib/supabase/go_true/user_handler.ex @@ -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) @@ -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() diff --git a/mix.exs b/mix.exs index a766bec..c13b6d2 100644 --- a/mix.exs +++ b/mix.exs @@ -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