After exhausting the first and most obvious solution of "just ask online", I had no choice but to fall back on the tried-and-true method of spending my weekend bashing my head against various desparate hypothesises in hopes one of them turns out to be correct (some people call this science, I call this spray-and-pray).
So here's the fix:
instead of:
@master_key Application.get_env(:simwms, :master_key)
It should've have been:
def master_key do
Application.get_env(:simwms, :master_key)
end
The exact reason for why master_key had to be a function def instead of a module attribute is because, on compilation of the code, @master_key
would be set before Application
even had a chance to load all the configuration files. Elixir doesn't throw an error on this, and instead just carries on with @master_key
being nil the whole time. Meanwhile, the function definition version reads from the Application
only when the function is called; the on-demand nature of this thus ensures that the proper value is delivered in the plug.
Don't use module attributes for anything other than literals.
I don't think this is a correct explanation.
Did you recompile the app after config's env is set?