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/token.ex | |
parent | updates (diff) |
format.
Diffstat (limited to 'lib/nola/token.ex')
-rw-r--r-- | lib/nola/token.ex | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/nola/token.ex b/lib/nola/token.ex index 179bed2..f4fdd86 100644 --- a/lib/nola/token.ex +++ b/lib/nola/token.ex @@ -2,15 +2,15 @@ defmodule Nola.Token do use GenServer def start_link() do - GenServer.start_link(__MODULE__, [], [name: __MODULE__]) + GenServer.start_link(__MODULE__, [], name: __MODULE__) end def lookup(id) do - with \ - [{_, cred, date}] <- :ets.lookup(__MODULE__.ETS, id), - IO.inspect("cred: #{inspect cred} valid for #{inspect date} now #{inspect DateTime.utc_now()}"), - d when d > 0 <- DateTime.diff(date, DateTime.utc_now()) - do + with [{_, cred, date}] <- :ets.lookup(__MODULE__.ETS, id), + IO.inspect( + "cred: #{inspect(cred)} valid for #{inspect(date)} now #{inspect(DateTime.utc_now())}" + ), + d when d > 0 <- DateTime.diff(date, DateTime.utc_now()) do {:ok, cred} else err -> {:error, err} @@ -22,17 +22,21 @@ defmodule Nola.Token do end def init(_) do - ets = :ets.new(__MODULE__.ETS, [:ordered_set, :named_table, :protected, {:read_concurrency, true}]) + ets = + :ets.new(__MODULE__.ETS, [:ordered_set, :named_table, :protected, {:read_concurrency, true}]) + {:ok, ets} end def handle_call({:new, cred}, _, ets) do id = Nola.UserTrack.Id.large_id() - expire = DateTime.utc_now() - |> DateTime.add(15*60, :second) + + expire = + DateTime.utc_now() + |> DateTime.add(15 * 60, :second) + obj = {id, cred, expire} :ets.insert(ets, obj) {:reply, {:ok, id}, ets} end - end |