Use secret_key_base as token_signing_secret

I have the following code in lib/example/accounts/user.ex:
tokens do
enabled? true
token_resource Example.Accounts.Token
signing_secret fn _, _ ->
System.fetch_env("TOKEN_SIGNING_SECRET")
end
end
tokens do
enabled? true
token_resource Example.Accounts.Token
signing_secret fn _, _ ->
System.fetch_env("TOKEN_SIGNING_SECRET")
end
end
Is there a way to use the secret_key_base which is already set in the Phoenix Application config instead of System.fetch_env("TOKEN_SIGNING_SECRET")?
5 Replies
frankdugan3
frankdugan3•3y ago
I think you'd just use Application.fetch_env() to get your endpoint's secret_key_base, right?
talha-azeem
talha-azeem•3y ago
but why do you want to use secret key base? defining the token signing secret in config works fine.
csos95
csos95•3y ago
Application.get_env(:my_app, MyAppWeb.Endpoint)[:secret_key_base]
frankdugan3
frankdugan3•3y ago
I would use fetch_env, as you'd want it to crash if there was no token defined. You I guess that syntax would fail as well, since you're using access pattern... Nvm. 😄
Stefan Wintermeyer
Stefan WintermeyerOP•3y ago
Thank you!

Did you find this page helpful?