Login per email token. With logout of previous account if already logged in.

This commit is contained in:
2026-02-18 15:01:31 +01:00
parent 02b473bbf1
commit 55c128e25e
6 changed files with 71 additions and 4 deletions

View File

@ -12,6 +12,23 @@ defmodule BeetRoundServerWeb.UserSessionController do
create(conn, params, "Welcome back!")
end
def login(conn, %{"token" => token}) do
IO.puts("Login via token:")
IO.inspect(token)
UserAuth.log_out_user_without_redirect(conn)
if user = Accounts.get_user_by_email_token(token) do
conn
|> put_flash(:info, "Login successful!")
|> UserAuth.log_in_without_creating_cookie(user)
else
conn
|> put_flash(:error, "Invalid token")
|> redirect(to: ~p"/")
end
end
# magic link login
defp create(conn, %{"user" => %{"token" => token} = user_params}, info) do
case Accounts.login_user_by_magic_link(token) do