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

@ -125,6 +125,27 @@ defmodule BeetRoundServer.Accounts.UserToken do
end
end
def verify_email_token_query(token, context) do
case Base.url_decode64(token, padding: false) do
{:ok, decoded_token} ->
hashed_token = :crypto.hash(@hash_algorithm, decoded_token)
days = days_for_context(context)
query =
from token in by_token_and_context_query(hashed_token, context),
join: user in assoc(token, :user),
where: token.inserted_at > ago(^days, "day") and token.sent_to == user.email,
select: user
{:ok, query}
:error ->
:error
end
end
defp days_for_context("session"), do: @session_validity_in_days
@doc """
Checks if the token is valid and returns its underlying lookup query.