I have a Phoenix application that uses Phoenix.Token
to sign and verify tokens.
This works fine within the app itself, but I get a strange error when trying to use Phoenix.Token
from a Mix task.
Here's a minimal example:
defmodule Mix.Tasks.SignSomething do
use Mix.Task
alias MyApp.Endpoint
@shortdoc "sign something"
def run(_args) do
IO.inspect Phoenix.Token.sign(Endpoint, "key", "val")
end
end
When I run this task, I see:
** (ArgumentError) argument error
(stdlib) :ets.lookup(MyApp.Endpoint, :secret_key_base)
lib/phoenix/endpoint.ex:505: Mealthy.Web.Endpoint.config/2
(phoenix) lib/phoenix/token.ex:201: Phoenix.Token.get_endpoint_key_base/1
This appears to imply that I haven't configured :secret_key_base
, but that's not true; it's in config.exs
, and if I IO.puts
directly after configuring it, I see that output.
How do I fix this?