diff options
author | Jordan Bracco <href@random.sh> | 2025-06-25 19:22:59 +0200 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2025-06-25 19:22:59 +0200 |
commit | c934e79e5852e05f714b2d542cc2678e287c49b8 (patch) | |
tree | 55779a0168260fce03e4775eacdd613ffc945588 /lib/nola/auth_token.ex | |
parent | updates (diff) |
format.
Diffstat (limited to 'lib/nola/auth_token.ex')
-rw-r--r-- | lib/nola/auth_token.ex | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/nola/auth_token.ex b/lib/nola/auth_token.ex index 9760ec7..0da4aab 100644 --- a/lib/nola/auth_token.ex +++ b/lib/nola/auth_token.ex @@ -2,7 +2,7 @@ defmodule Nola.AuthToken do use GenServer def start_link() do - GenServer.start_link(__MODULE__, [], [name: __MODULE__]) + GenServer.start_link(__MODULE__, [], name: __MODULE__) end def lookup(id) do @@ -13,6 +13,7 @@ defmodule Nola.AuthToken do case new(account, perks) do {:ok, id} -> NolaWeb.Router.Helpers.login_path(NolaWeb.Endpoint, :token, id) + error -> error end @@ -22,6 +23,7 @@ defmodule Nola.AuthToken do case new(account, perks) do {:ok, id} -> NolaWeb.Router.Helpers.login_url(NolaWeb.Endpoint, :token, id) + error -> error end @@ -32,15 +34,14 @@ defmodule Nola.AuthToken do end def init(_) do - {:ok, Map.new} + {:ok, Map.new()} end def handle_call({:lookup, id}, _, state) do IO.inspect(state) - with \ - {account, date, perks} <- Map.get(state, id), - d when d > 0 <- DateTime.diff(date, DateTime.utc_now()) - do + + with {account, date, perks} <- Map.get(state, id), + d when d > 0 <- DateTime.diff(date, DateTime.utc_now()) do {:reply, {:ok, account, perks}, Map.delete(state, id)} else x -> @@ -51,9 +52,11 @@ defmodule Nola.AuthToken do def handle_call({:new, account, perks}, _, state) do id = Nola.UserTrack.Id.token() - expire = DateTime.utc_now() - |> DateTime.add(15*60, :second) + + expire = + DateTime.utc_now() + |> DateTime.add(15 * 60, :second) + {:reply, {:ok, id}, Map.put(state, id, {account, expire, perks})} end - end |