From 9ade1e978d9c1bf165059d0e1f4bb03562b02edb Mon Sep 17 00:00:00 2001 From: James Harton Date: Mon, 18 Sep 2023 11:28:40 +1200 Subject: [PATCH] fix: support generating tokens for other strategies. --- lib/ash_authentication/generate_token_change.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ash_authentication/generate_token_change.ex b/lib/ash_authentication/generate_token_change.ex index 4940207..b3ceffc 100644 --- a/lib/ash_authentication/generate_token_change.ex +++ b/lib/ash_authentication/generate_token_change.ex @@ -23,7 +23,8 @@ defmodule AshAuthentication.GenerateTokenChange do end) end - defp generate_token(purpose, record, strategy) when purpose in [:user, :sign_in] do + defp generate_token(purpose, record, strategy) + when purpose in [:user, :sign_in] and is_integer(strategy.sign_in_token_lifetime) do {:ok, token, _claims} = Jwt.token_for_user(record, %{"purpose" => to_string(purpose)}, token_lifetime: strategy.sign_in_token_lifetime @@ -31,4 +32,10 @@ defmodule AshAuthentication.GenerateTokenChange do Ash.Resource.put_metadata(record, :token, token) end + + defp generate_token(purpose, record, _strategy) do + {:ok, token, _claims} = Jwt.token_for_user(record, %{"purpose" => to_string(purpose)}) + + Ash.Resource.put_metadata(record, :token, token) + end end