feat(auth): add auth through phx.gen.auth

This commit is contained in:
2024-10-22 00:19:26 +00:00
parent 64016ef098
commit 3f40253559
30 changed files with 3377 additions and 9 deletions

View File

@@ -35,4 +35,30 @@ defmodule SlaxWeb.ConnCase do
Slax.DataCase.setup_sandbox(tags)
{:ok, conn: Phoenix.ConnTest.build_conn()}
end
@doc """
Setup helper that registers and logs in users.
setup :register_and_log_in_user
It stores an updated connection and a registered user in the
test context.
"""
def register_and_log_in_user(%{conn: conn}) do
user = Slax.AccountsFixtures.user_fixture()
%{conn: log_in_user(conn, user), user: user}
end
@doc """
Logs the given `user` into the `conn`.
It returns an updated `conn`.
"""
def log_in_user(conn, user) do
token = Slax.Accounts.generate_user_session_token(user)
conn
|> Phoenix.ConnTest.init_test_session(%{})
|> Plug.Conn.put_session(:user_token, token)
end
end