diff --git a/README.md b/README.md index 126afa4..880ae83 100644 --- a/README.md +++ b/README.md @@ -1 +1,34 @@ -# Supabase Auth (GoTrue) +# Supabase GoTrue + +[Auth](https://supabase.com/docs/guides/auth) implementation for the `supabase_potion` SDK in Elixir. + +## Installation + +```elixir +def deps do + [ + {:supabase_potion, "~> 0.3"}, + {:supabase_gotrue, "~> 0.2"} + ] +end +``` + +## Usage + +Firstly you need to initialize your Supabase client(s) as can be found on the [supabase_potion documentation](https://hexdocs.pm/supabase_potion/Supabase.html#module-starting-a-client): + +```elixir +iex> Supabase.init_client(%{name: Conn, conn: %{base_url: "", api_key: ""}}) +{:ok, #PID<>} +``` + +Now you can pass the Client to the `Supabase.GoTrue` functions as a `PID` or the name that was registered on the client initialization: + +```elixir +iex> Supabase.GoTrue.sign_in_with_password(pid | client_name, %{} = params) +``` + +This implementation also exposes an `Supaabse.GoTrue.Admin` function to interact with users with super powers: +```elixir +iex> Supabase.GoTrue.Admin.create_user(pid | client_name, %{} = params) +``` diff --git a/lib/supabase/go_true.ex b/lib/supabase/go_true.ex index bcfb2a9..85c3136 100644 --- a/lib/supabase/go_true.ex +++ b/lib/supabase/go_true.ex @@ -1,5 +1,14 @@ defmodule Supabase.GoTrue do - @moduledoc false + @moduledoc """ + This module provides the functionality to interact with the GoTrue API, + allowing management of users, sessions, and authentication. + + It also aims to provide integrations with Plug and Phoenix LiveView applications. + + For detailed information about the GoTrue API, check the official documentation at https://supabase.io/docs/reference/javascript/auth-api + + And also refer to functions and submodules documentation for more information. + """ import Supabase.Client, only: [is_client: 1] @@ -18,6 +27,18 @@ defmodule Supabase.GoTrue do @behaviour Supabase.GoTrueBehaviour + @doc """ + Get the user associated with the current session. + + ## Parameters + - `client` - The `Supabase` client to use for the request. + - `session` - The session to use for the request. Check `Supabase.GoTrue.Session` for more information. + + ## Examples + iex> session = %Supabase.GoTrue.Session{access_token: "example_token"} + iex> Supabase.GoTrue.get_user(pid | client_name, session) + {:ok, %Supabase.GoTrue.User{}} + """ @impl true def get_user(client, %Session{} = session) do with {:ok, client} <- Client.retrieve_client(client), @@ -26,6 +47,18 @@ defmodule Supabase.GoTrue do end end + @doc """ + Signs in a user with ID token. + + ## Parameters + - `client` - The `Supabase` client to use for the request. + - `credentials` - The credentials to use for the sign in. Check `Supabase.GoTrue.Schemas.SignInWithIdToken` for more information. + + ## Examples + iex> credentials = %Supabase.GoTrue.SignInWithIdToken{} + iex> Supabase.GoTrue.sign_in_with_id_token(pid | client_name, credentials) + {:ok, %Supabase.GoTrue.User{}} + """ @impl true def sign_in_with_id_token(client, credentials) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), @@ -34,6 +67,18 @@ defmodule Supabase.GoTrue do end end + @doc """ + Signs in a user with OAuth. + + ## Parameters + - `client` - The `Supabase` client to use for the request. + - `credentials` - The credentials to use for the sign in. Check `Supabase.GoTrue.Schemas.SignInWithOauth` for more information. + + ## Examples + iex> credentials = %Supabase.GoTrue.SignInWithOauth{} + iex> Supabase.GoTrue.sign_in_with_oauth(pid | client_name, credentials) + {:ok, atom, URI.t()} + """ @impl true def sign_in_with_oauth(client, credentials) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), @@ -43,6 +88,18 @@ defmodule Supabase.GoTrue do end end + @doc """ + Signs in a user with OTP. + + ## Parameters + - `client` - The `Supabase` client to use for the request. + - `credentials` - The credentials to use for the sign in. Check `Supabase.GoTrue.Schemas.SignInWithOTP` for more information. + + ## Examples + iex> credentials = %Supabase.GoTrue.SignInWithOTP{} + iex> Supabase.GoTrue.sign_in_with_otp(pid | client_name, credentials) + {:ok, %Supabase.GoTrue.Session{}} + """ @impl true def sign_in_with_otp(client, credentials) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), @@ -51,6 +108,18 @@ defmodule Supabase.GoTrue do end end + @doc """ + Verifies an OTP code. + + ## Parameters + - `client` - The `Supabase` client to use for the request. + - `params` - The parameters to use for the verification. Check `Supabase.GoTrue.Schemas.VerifyOTP` for more information. + + ## Examples + iex> params = %Supabase.GoTrue.VerifyOTP{} + iex> Supabase.GoTrue.verify_otp(pid | client_name, params) + {:ok, %Supabase.GoTrue.Session{}} + """ @impl true def verify_otp(client, params) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), @@ -59,6 +128,18 @@ defmodule Supabase.GoTrue do end end + @doc """ + Signs in a user with SSO. + + ## Parameters + - `client` - The `Supabase` client to use for the request. + - `credentials` - The credentials to use for the sign in. Check `Supabase.GoTrue.Schemas.SignInWithSSO` for more information. + + ## Examples + iex> credentials = %Supabase.GoTrue.SignInWithSSO{} + iex> Supabase.GoTrue.sign_in_with_sso(pid | client_name, credentials) + {:ok, %Supabase.GoTrue.User{}} + """ @impl true def sign_in_with_sso(client, credentials) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), @@ -67,6 +148,18 @@ defmodule Supabase.GoTrue do end end + @doc """ + Signs in a user with email/phone and password. + + ## Parameters + - `client` - The `Supabase` client to use for the request. + - `credentials` - The credentials to use for the sign in. Check `Supabase.GoTrue.Schemas.SignInWithPassword` for more information. + + ## Examples + iex> credentials = %Supabase.GoTrue.SignInWithPassword{} + iex> Supabase.GoTrue.sign_in_with_password(pid | client_name, credentials) + {:ok, %Supabase.GoTrue.Session{}} + """ @impl true def sign_in_with_password(client, credentials) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), @@ -76,6 +169,18 @@ defmodule Supabase.GoTrue do end end + @doc """ + Signs up a user with email/phone and password. + + ## Parameters + - `client` - The `Supabase` client to use for the request. + - `credentials` - The credentials to use for the sign up. Check `Supabase.GoTrue.Schemas.SignUpWithPassword` for more information. + + ## Examples + iex> credentials = %Supabase.GoTrue.SignUpWithPassword{} + iex> Supabase.GoTrue.sign_up(pid | client_name, credentials) + {:ok, %Supabase.GoTrue.User{}} + """ @impl true def sign_up(client, credentials) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), diff --git a/lib/supabase/go_true/admin.ex b/lib/supabase/go_true/admin.ex index c975d51..e9afcbe 100644 --- a/lib/supabase/go_true/admin.ex +++ b/lib/supabase/go_true/admin.ex @@ -1,5 +1,10 @@ defmodule Supabase.GoTrue.Admin do - @moduledoc false + @moduledoc """ + Admin module for GoTrue. This module provides functions to interact with the GoTrue admin API, + like signing out a user, inviting a user, and generating a link. + + You can find more information about the GoTrue admin API at https://supabase.io/docs/reference/javascript/auth-admin-api + """ import Supabase.Client, only: [is_client: 1] @@ -17,6 +22,18 @@ defmodule Supabase.GoTrue.Admin do @scopes ~w[global local others]a + @doc """ + Signs out a user from the GoTrue admin API. + + ## Parameters + * `client` - The `Supabase` client to use for the request. + * `session` - The session to sign out, often retrieved from a sign in function. + * `scope` - The scope to sign out the user from. Can be one of `global`, `local`, or `others`. + + ## Examples + iex> session = %Session{access_token: "access_token"} + iex> Supabase.GoTrue.Admin.sign_out(pid | client_name, session, "global") + """ @impl true def sign_out(client, %Session{} = session, scope) when is_client(client) and scope in @scopes do with {:ok, client} <- Client.retrieve_client(client) do @@ -29,6 +46,17 @@ defmodule Supabase.GoTrue.Admin do end end + @doc """ + Invites a user to the GoTrue admin API. + + ## Parameters + * `client` - The `Supabase` client to use for the request. + * `email` - The email of the user to invite. + * `options` - The options to use for the invite. See `Supabase.GoTrue.Schemas.InviteUserParams` for more information. + + ## Examples + iex> Supabase.GoTrue.Admin.invite_user_by_email(pid | client_name, "john@example.com", %{}) + """ @impl true def invite_user_by_email(client, email, options \\ %{}) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), @@ -38,6 +66,16 @@ defmodule Supabase.GoTrue.Admin do end end + @doc """ + Generates a link for the GoTrue admin API. + + ## Parameters + * `client` - The `Supabase` client to use for the request. + * `attrs` - The attributes to use for the link. See `Supabase.GoTrue.Schemas.GenerateLink` for more information. + + ## Examples + iex> Supabase.GoTrue.Admin.generate_link(pid | client_name, %{}) + """ @impl true def generate_link(client, attrs) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), @@ -47,6 +85,16 @@ defmodule Supabase.GoTrue.Admin do end end + @doc """ + Creates a user in the GoTrue admin API. + + ## Parameters + * `client` - The `Supabase` client to use for the request. + * `attrs` - The attributes to use for the user. See `Supabase.GoTrue.Schemas.AdminUserParams` for more information. + + ## Examples + iex> Supabase.GoTrue.Admin.create_user(pid | client_name, %{}) + """ @impl true def create_user(client, attrs) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), @@ -56,6 +104,17 @@ defmodule Supabase.GoTrue.Admin do end end + @doc """ + Deletes a user in the GoTrue admin API. + + ## Parameters + * `client` - The `Supabase` client to use for the request. + * `user_id` - The ID of the user to delete. + * `opts` - Controls if the user should be soft deleted or not. + + ## Examples + iex> Supabase.GoTrue.Admin.update_user(pid | client_name, "user_id", %{}) + """ @impl true def delete_user(client, user_id, opts \\ [should_soft_delete: false]) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), @@ -64,6 +123,16 @@ defmodule Supabase.GoTrue.Admin do end end + @doc """ + Gets a user by ID in the GoTrue admin API. + + ## Parameters + * `client` - The `Supabase` client to use for the request. + * `user_id` - The ID of the user to get. + + ## Examples + iex> Supabase.GoTrue.Admin.get_user_by_id(pid | client_name, "user_id") + """ @impl true def get_user_by_id(client, user_id) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), @@ -72,6 +141,16 @@ defmodule Supabase.GoTrue.Admin do end end + @doc """ + Lists users in the GoTrue admin API. + + ## Parameters + * `client` - The `Supabase` client to use for the request. + * `params` - The parameters to use for the list. See `Supabase.GoTrue.Schemas.PaginationParams` for more information. + + ## Examples + iex> Supabase.GoTrue.Admin.list_users(pid | client_name, %{}) + """ @impl true def list_users(client, params \\ %{}) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), @@ -115,6 +194,17 @@ defmodule Supabase.GoTrue.Admin do end) end + @doc """ + Updates a user in the GoTrue admin API. + + ## Parameters + * `client` - The `Supabase` client to use for the request. + * `user_id` - The ID of the user to update. + * `attrs` - The attributes to use for the user. See `Supabase.GoTrue.Schemas.AdminUserParams` for more information. + + ## Examples + iex> Supabase.GoTrue.Admin.update_user(pid | client_name, "user_id", %{}) + """ @impl true def update_user_by_id(client, user_id, attrs) when is_client(client) do with {:ok, client} <- Client.retrieve_client(client), diff --git a/lib/supabase/go_true/auth.ex b/lib/supabase/go_true/auth.ex index 504b941..e2f1560 100644 --- a/lib/supabase/go_true/auth.ex +++ b/lib/supabase/go_true/auth.ex @@ -1,5 +1,7 @@ defmodule Supabase.GoTrue.Auth do - @moduledoc false + @moduledoc """ + This module contains the authentication logic for Supabase GoTrue. + """ use Ecto.Schema diff --git a/lib/supabase/go_true/pkce.ex b/lib/supabase/go_true/pkce.ex index c4cdc02..2f69d68 100644 --- a/lib/supabase/go_true/pkce.ex +++ b/lib/supabase/go_true/pkce.ex @@ -1,5 +1,7 @@ defmodule Supabase.GoTrue.PKCE do - @moduledoc false + @moduledoc """ + This module is used to generate PKCE (Proof Key for Code Exchange) values. + """ @verifier_length 56 diff --git a/lib/supabase/go_true/plug.ex b/lib/supabase/go_true/plug.ex index 060386d..9e77836 100644 --- a/lib/supabase/go_true/plug.ex +++ b/lib/supabase/go_true/plug.ex @@ -29,7 +29,7 @@ defmodule Supabase.GoTrue.Plug do |> configure_session(renew: true) end - def sig_in(%Conn{} = conn, client, attrs) when is_client(client) do + def sign_in(%Conn{} = conn, client, attrs) when is_client(client) do case maybe_sign_in(conn, client, attrs) do {:ok, session} -> put_session_token(conn, session.access_token) _ -> conn diff --git a/lib/supabase/go_true/schemas/admin_user_params.ex b/lib/supabase/go_true/schemas/admin_user_params.ex index d7605fa..cdbe004 100644 --- a/lib/supabase/go_true/schemas/admin_user_params.ex +++ b/lib/supabase/go_true/schemas/admin_user_params.ex @@ -1,5 +1,18 @@ defmodule Supabase.GoTrue.Schemas.AdminUserParams do - @moduledoc false + @moduledoc """ + Admin user params schema. This schema is used to validate and parse the parameters for creating a new admin user. + + ## Fields + * `app_metadata` - The metadata to associate with the user. + * `email_confirm` - Whether the user's email is confirmed. + * `phone_confirm` - Whether the user's phone is confirmed. + * `ban_duration` - The duration of the user's ban. + * `role` - The user's role. + * `email` - The user's email. + * `phone` - The user's phone. + * `password` - The user's password. + * `nonce` - The user's nonce. + """ import Ecto.Changeset import Supabase.GoTrue.Validations diff --git a/lib/supabase/go_true/schemas/generate_link.ex b/lib/supabase/go_true/schemas/generate_link.ex index 9c18fbf..c2f523c 100644 --- a/lib/supabase/go_true/schemas/generate_link.ex +++ b/lib/supabase/go_true/schemas/generate_link.ex @@ -1,5 +1,23 @@ defmodule Supabase.GoTrue.Schemas.GenerateLink do - @moduledoc false + @moduledoc """ + This module is responsible for generating links for different actions. + + ## Fields + * `action_link` - The link to the action. + * `email_otp` - The email one-time password. + * `hashed_token` - The hashed token. + * `redirect_to` - The redirect URL. + * `verification_type` - The type of verification. + - `signup` + - `invite` + - `magicLink` + - `recovery` + - `email_change_current` + - `email_change_new` + * `options` - The options for the link. + - `data` - The data for the link. + - `redirect_to` - The redirect URL. + """ import Ecto.Changeset diff --git a/lib/supabase/go_true/schemas/invite_user_params.ex b/lib/supabase/go_true/schemas/invite_user_params.ex index 9831f2e..ede5c33 100644 --- a/lib/supabase/go_true/schemas/invite_user_params.ex +++ b/lib/supabase/go_true/schemas/invite_user_params.ex @@ -1,5 +1,11 @@ defmodule Supabase.GoTrue.Schemas.InviteUserParams do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the parameters for inviting a new user. + + ## Fields + * `data` - The data for the link. + * `redirect_to` - The redirect URL. + """ use Supabase, :schema diff --git a/lib/supabase/go_true/schemas/pagination_params.ex b/lib/supabase/go_true/schemas/pagination_params.ex index b5e6ecb..6f4e7f3 100644 --- a/lib/supabase/go_true/schemas/pagination_params.ex +++ b/lib/supabase/go_true/schemas/pagination_params.ex @@ -1,5 +1,11 @@ defmodule Supabase.GoTrue.Schemas.PaginationParams do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the parameters for pagination. + + ## Fields + * `page` - The current page. + * `per_page` - The number of items per page. + """ use Ecto.Schema diff --git a/lib/supabase/go_true/schemas/sign_in_request.ex b/lib/supabase/go_true/schemas/sign_in_request.ex index f1a4377..a94f811 100644 --- a/lib/supabase/go_true/schemas/sign_in_request.ex +++ b/lib/supabase/go_true/schemas/sign_in_request.ex @@ -1,5 +1,16 @@ defmodule Supabase.GoTrue.Schemas.SignInRequest do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the parameters for signing in a user. + + ## Fields + + Fields depends on the sign in method, so check their modules to + see the available fields. + - Sign in with ID Token: `Supabase.GoTrue.Schemas.SignInWithIdToken` + - Sign in with OTP: `Supabase.GoTrue.Schemas.SignInWithOTP` + - Sign in with Password: `Supabase.GoTrue.Schemas.SignInWithPassword` + - Sign in with SSO: `Supabase.GoTrue.Schemas.SignInWithSSO` + """ use Ecto.Schema diff --git a/lib/supabase/go_true/schemas/sign_in_with_id_token.ex b/lib/supabase/go_true/schemas/sign_in_with_id_token.ex index 6a0d2b4..64fa673 100644 --- a/lib/supabase/go_true/schemas/sign_in_with_id_token.ex +++ b/lib/supabase/go_true/schemas/sign_in_with_id_token.ex @@ -1,5 +1,15 @@ defmodule Supabase.GoTrue.Schemas.SignInWithIdToken do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the parameters for signing in with an ID token. + + ## Fields + * `provider` - The provider. + * `token` - The token. + * `access_token` - The access token. + * `nonce` - The nonce. + * `options` - The options. + - `captcha_token` - The captcha token. + """ use Supabase, :schema diff --git a/lib/supabase/go_true/schemas/sign_in_with_oauth.ex b/lib/supabase/go_true/schemas/sign_in_with_oauth.ex index a049b4e..67fe2a6 100644 --- a/lib/supabase/go_true/schemas/sign_in_with_oauth.ex +++ b/lib/supabase/go_true/schemas/sign_in_with_oauth.ex @@ -1,5 +1,15 @@ defmodule Supabase.GoTrue.Schemas.SignInWithOauth do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the parameters for signing in with OAuth. + + ## Fields + * `provider` - The provider. + * `options` - The options. + - `redirect_to` - The redirect URL. + - `scopes` - The scopes. + - `query_params` - The query parameters. + - `skip_browser_redirect` - Whether to skip the browser redirect. + """ use Supabase, :schema diff --git a/lib/supabase/go_true/schemas/sign_in_with_otp.ex b/lib/supabase/go_true/schemas/sign_in_with_otp.ex index bafe3ea..2308596 100644 --- a/lib/supabase/go_true/schemas/sign_in_with_otp.ex +++ b/lib/supabase/go_true/schemas/sign_in_with_otp.ex @@ -1,5 +1,16 @@ defmodule Supabase.GoTrue.Schemas.SignInWithOTP do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the parameters for signing in with OTP. + + ## Fields + * `email` - The user's email. + * `phone` - The user's phone. + * `options` - The options for signing in with OTP. + - `data` - The data for the sign in. + - `email_redirect_to` - The redirect URL for the email. + - `captcha_token` - The captcha token. + - `channel` - The channel for the OTP. + """ use Supabase, :schema diff --git a/lib/supabase/go_true/schemas/sign_in_with_password.ex b/lib/supabase/go_true/schemas/sign_in_with_password.ex index cae15c8..f8b1814 100644 --- a/lib/supabase/go_true/schemas/sign_in_with_password.ex +++ b/lib/supabase/go_true/schemas/sign_in_with_password.ex @@ -1,5 +1,15 @@ defmodule Supabase.GoTrue.Schemas.SignInWithPassword do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the parameters for signing in with a password. + + ## Fields + * `email` - The user's email. + * `phone` - The user's phone. + * `password` - The user's password. + * `options` - The options for the sign in. + - `data` - The data for the sign in. + - `captcha_token` - The captcha token. + """ use Ecto.Schema diff --git a/lib/supabase/go_true/schemas/sign_in_with_sso.ex b/lib/supabase/go_true/schemas/sign_in_with_sso.ex index 28146b2..436e8c9 100644 --- a/lib/supabase/go_true/schemas/sign_in_with_sso.ex +++ b/lib/supabase/go_true/schemas/sign_in_with_sso.ex @@ -1,5 +1,14 @@ defmodule Supabase.GoTrue.Schemas.SignInWithSSO do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the parameters for signing in with SSO. + + ## Fields + * `provider_id` - The provider ID. + * `domain` - The domain. + * `options` - The options. + - `redirect_to` - The redirect URL. + - `captcha_token` - The captcha token. + """ use Supabase, :schema diff --git a/lib/supabase/go_true/schemas/sign_up_request.ex b/lib/supabase/go_true/schemas/sign_up_request.ex index 035a24d..05a0418 100644 --- a/lib/supabase/go_true/schemas/sign_up_request.ex +++ b/lib/supabase/go_true/schemas/sign_up_request.ex @@ -1,5 +1,17 @@ defmodule Supabase.GoTrue.Schemas.SignUpRequest do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the parameters for signing up a new user. + + ## Fields + * `email` - The user's email. + * `phone` - The user's phone. + * `password` - The user's password. + * `data` - The user's data. + * `code_challenge` - The user's code challenge. + * `code_challenge_method` - The user's code challenge method. + * `gotrue_meta_security` - The user's gotrue meta security. + - `captcha_token` - The user's captcha token. + """ use Ecto.Schema diff --git a/lib/supabase/go_true/schemas/sign_up_with_password.ex b/lib/supabase/go_true/schemas/sign_up_with_password.ex index 1482765..c1c3f72 100644 --- a/lib/supabase/go_true/schemas/sign_up_with_password.ex +++ b/lib/supabase/go_true/schemas/sign_up_with_password.ex @@ -4,6 +4,7 @@ defmodule Supabase.GoTrue.Schemas.SignUpWithPassword do use Ecto.Schema import Ecto.Changeset + import Supabase.GoTrue.Validations @type options :: %__MODULE__.Options{ email_redirect_to: URI.t() | nil, @@ -48,7 +49,7 @@ defmodule Supabase.GoTrue.Schemas.SignUpWithPassword do |> cast(attrs, [:email, :password, :phone]) |> cast_embed(:options, with: &options_changeset/2, required: false) |> maybe_put_default_options() - |> validate_email_or_phone() + |> validate_required_inclusion([:email, :phone]) |> validate_required([:password]) end @@ -66,29 +67,6 @@ defmodule Supabase.GoTrue.Schemas.SignUpWithPassword do cast(options, attrs, ~w[email_redirect_to data captcha_token]a) end - defp validate_email_or_phone(changeset) do - email = get_change(changeset, :email) - phone = get_change(changeset, :phone) - - case {email, phone} do - {nil, nil} -> - changeset - |> add_error(:email, "or phone can't be blank") - |> add_error(:phone, "or email can't be blank") - - {email, nil} when is_binary(email) -> - changeset - - {nil, phone} when is_binary(phone) -> - changeset - - {email, phone} when is_binary(email) and is_binary(phone) -> - changeset - |> add_error(:email, "can't be given with phone") - |> add_error(:phone, "can't be given with email") - end - end - @spec parse(map) :: {:ok, t} | {:error, Ecto.Changeset.t()} def parse(attrs) do attrs diff --git a/lib/supabase/go_true/schemas/verify_otp.ex b/lib/supabase/go_true/schemas/verify_otp.ex index c06b72a..7f34eee 100644 --- a/lib/supabase/go_true/schemas/verify_otp.ex +++ b/lib/supabase/go_true/schemas/verify_otp.ex @@ -1,5 +1,32 @@ defmodule Supabase.GoTrue.Schemas.VerifyOTP do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the parameters for verifying an OTP. + + ## Fields + + ### Mobile OTP + * `phone` - The user's phone number. + * `token` - The OTP token. + * `type` - The type of OTP. + * `options` - The options for the OTP. + - `redirect_to` - The redirect URL. + - `captcha_token` - The captcha token. + + ### Email OTP + * `email` - The user's email. + * `token` - The OTP token. + * `type` - The type of OTP. + * `options` - The options for the OTP. + - `redirect_to` - The redirect URL. + - `captcha_token` - The captcha token. + + ### Token Hash + * `token_hash` - The token hash. + * `type` - The type of OTP. + * `options` - The options for the OTP. + - `redirect_to` - The redirect URL. + - `captcha_token` - The captcha token. + """ use Supabase, :schema diff --git a/lib/supabase/go_true/session.ex b/lib/supabase/go_true/session.ex index 4f19351..458de08 100644 --- a/lib/supabase/go_true/session.ex +++ b/lib/supabase/go_true/session.ex @@ -1,5 +1,17 @@ defmodule Supabase.GoTrue.Session do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the parameters for a session. + + ## Fields + * `provider_token` - The provider token. + * `provider_refresh_token` - The provider refresh token. + * `access_token` - The access token. + * `refresh_token` - The refresh token. + * `expires_in` - The expiration time. + * `expires_at` - The expiration date. + * `token_type` - The token type. + * `user` - The user. Check the `Supabase.GoTrue.User` schema for more information. + """ use Ecto.Schema diff --git a/lib/supabase/go_true/user.ex b/lib/supabase/go_true/user.ex index cefe90e..679fe04 100644 --- a/lib/supabase/go_true/user.ex +++ b/lib/supabase/go_true/user.ex @@ -1,5 +1,33 @@ defmodule Supabase.GoTrue.User do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the parameters for a user. + + ## Fields + * `id` - The user's ID. + * `app_metadata` - The metadata to associate with the user. + * `user_metadata` - The user's metadata. + * `aud` - The user's audience. + * `confirmation_sent_at` - The time the confirmation was sent. + * `recovery_sent_at` - The time the recovery was sent. + * `email_change_sent_at` - The time the email change was sent. + * `new_email` - The new email. + * `new_phone` - The new phone. + * `invited_at` - The time the user was invited. + * `action_link` - The action link. + * `email` - The user's email. + * `phone` - The user's phone. + * `created_at` - The time the user was created. + * `confirmed_at` - The time the user was confirmed. + * `email_confirmed_at` - The time the email was confirmed. + * `phone_confirmed_at` - The time the phone was confirmed. + * `last_sign_in_at` - The time the user last signed in. + * `last_sign_in_ip` - The user's last sign-in IP. + * `current_sign_in_at` - The time the user last signed in. + * `current_sign_in_ip` - The user's current sign-in IP. + * `sign_in_count` - The number of times the user has signed in. + * `factors` - The user's factors. Check the `Supabase.GoTrue.User.Factor` schema for more information. + * `identities` - The user's identities. Check the `Supabase.GoTrue.User.Identity` schema for more information. + """ use Ecto.Schema diff --git a/lib/supabase/go_true/user/factor.ex b/lib/supabase/go_true/user/factor.ex index 04cc512..1baa98a 100644 --- a/lib/supabase/go_true/user/factor.ex +++ b/lib/supabase/go_true/user/factor.ex @@ -1,5 +1,15 @@ defmodule Supabase.GoTrue.User.Factor do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the parameters for a user factor. + + ## Fields + * `friendly_name` - The friendly name of the factor. + * `factor_type` - The type of factor. + * `status` - The status of the factor. + * `created_at` - The creation date of the factor. + * `updated_at` - The last update date of the factor. + * `id` - The factor's ID. + """ use Ecto.Schema diff --git a/lib/supabase/go_true/user/identity.ex b/lib/supabase/go_true/user/identity.ex index 2d1cbb6..cc55f31 100644 --- a/lib/supabase/go_true/user/identity.ex +++ b/lib/supabase/go_true/user/identity.ex @@ -1,5 +1,16 @@ defmodule Supabase.GoTrue.User.Identity do - @moduledoc false + @moduledoc """ + This schema is used to validate and parse the identity of a user. + + ## Fields + * `id` - The user's ID. + * `user_id` - The user's ID. + * `provider` - The user's provider. + * `created_at` - The user's creation date. + * `updated_at` - The user's last update date. + * `identity_data` - The user's identity data. + * `last_sign_in_at` - The user's last sign-in date. + """ use Ecto.Schema diff --git a/mix.exs b/mix.exs index 1cb28c0..0c5ad5f 100644 --- a/mix.exs +++ b/mix.exs @@ -1,12 +1,12 @@ defmodule SupabaseAuth.MixProject do use Mix.Project - @version "0.1.0" - @source_url "https://github.com/zoedsoupe/supabase" + @version "0.2.1" + @source_url "https://github.com/zoedsoupe/gotrue-ex" def project do [ - app: :supabase_auth, + app: :supabase_gotrue, version: @version, elixir: "~> 1.15", start_permanent: Mix.env() == :prod,