Can't test authentication after configuring Ash AuthenticationPhoenix Tutorial

After following steps on the tutorial for configuring authentication with phoenix, im getting errors on the routes as if the AuthController was not working. When Accessing the main route http://localhost:4000 i get this error:
[info] GET /
[debug] Processing with CaseHolderWeb.PageController.home/2
Parameters: %{}
Pipelines: [:browser]
[info] Sent 500 in 220ms
[error] #PID<0.662.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.660.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /
** (exit) an exception was raised:
** (KeyError) key :current_user not found in: %{conn: %Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{flash: %{}, layout: false}, body_params: %{}, cookies: %{"CookieConsent" => "{stamp:%27WdyDXvmkdlf9QmCIMoMkq9g4y0EWBHNxudi5fJHBo3A8quW4xYK60g==%27%2Cnecessary:true%2Cpreferences:false%2Cstatistics:false%2Cmarketing:false%2Cver:1%2Cutc:1667260198396%2Cregion:%27us-06%27}", "Pycharm-e2283c24" => "42a5d6d9-0c58-42cd-a3ef-fe39e716c15c", "Webstorm-45dcd7e3" => "e3033df7-0f7e-4297-9158-d5e20a4f64f0",
[info] GET /
[debug] Processing with CaseHolderWeb.PageController.home/2
Parameters: %{}
Pipelines: [:browser]
[info] Sent 500 in 220ms
[error] #PID<0.662.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.660.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /
** (exit) an exception was raised:
** (KeyError) key :current_user not found in: %{conn: %Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{flash: %{}, layout: false}, body_params: %{}, cookies: %{"CookieConsent" => "{stamp:%27WdyDXvmkdlf9QmCIMoMkq9g4y0EWBHNxudi5fJHBo3A8quW4xYK60g==%27%2Cnecessary:true%2Cpreferences:false%2Cstatistics:false%2Cmarketing:false%2Cver:1%2Cutc:1667260198396%2Cregion:%27us-06%27}", "Pycharm-e2283c24" => "42a5d6d9-0c58-42cd-a3ef-fe39e716c15c", "Webstorm-45dcd7e3" => "e3033df7-0f7e-4297-9158-d5e20a4f64f0",
And if I get on the 'sign-in' page i can only see the header for the page. I'm new with elixir and phoenix so this might be a problem with me not ocnfiguring something correctly but i've triple checked most things and cant get it working.
No description
No description
28 Replies
ZachDaniel
ZachDaniel•3y ago
Do you have the api that contains your user in config :your_app, :ash_apis ? And have you added your user/token resource to the registry for that app? i.e config :your_app, :ash_apis, [YourApp.Accounts]
vedha.ivan
vedha.ivanOP•3y ago
thank you @Zach Daniel this helped a bit, i added
config :case_holder,
ash_apis: [CaseHolder.Holder, CaseHolder.Accounts]
config :case_holder,
ash_apis: [CaseHolder.Holder, CaseHolder.Accounts]
I only had the first api registered
vedha.ivan
vedha.ivanOP•3y ago
i can see the home page correctly
No description
ZachDaniel
ZachDaniel•3y ago
Can you link me to the guide you're following?
vedha.ivan
vedha.ivanOP•3y ago
but the sign in route shows me this yes
ZachDaniel
ZachDaniel•3y ago
Did you do that step?
vedha.ivan
vedha.ivanOP•3y ago
oh i think i missed that
No description
vedha.ivan
vedha.ivanOP•3y ago
now i think its working
ZachDaniel
ZachDaniel•3y ago
Nice! I think you need the tailwind config set up as well
vedha.ivan
vedha.ivanOP•3y ago
i might have something else missing here, sign in and sign out works correctly, but when there is an error on authentication (wrong password) i get this:
No description
No description
vedha.ivan
vedha.ivanOP•3y ago
i also finished implementing the reset password interactions, but i get this when accessing the reset url
vedha.ivan
vedha.ivanOP•3y ago
No description
ZachDaniel
ZachDaniel•3y ago
Can you check for updates to ash_authentication and ash_authentication_phoenix ? Did you do the part about creating the failure.html file? with <h1 class="text-2xl">Authentication Error</h1> in it
vedha.ivan
vedha.ivanOP•3y ago
sure, i have these versions on the libs side: ash 2.6.27 ash_authentication 3.10.2 ash_authentication_phoenix 1.6.5 ash_phoenix 1.2.11 ash_postgres 1.3.18 i also created the failure.html.heex template thank you for reading this
No description
No description
No description
ZachDaniel
ZachDaniel•3y ago
Are you still getting the :socket is a reserved assign error?
vedha.ivan
vedha.ivanOP•3y ago
yes, no changes
No description
ZachDaniel
ZachDaniel•3y ago
🤔 Can you try using ash_authentication_phoenix main? {:ash_authentication_phoenix, github: "team-alembic/ash_authentication_phoenix"}
vedha.ivan
vedha.ivanOP•3y ago
sure, let me try this, it worked the reset password url now showed the correct form
ZachDaniel
ZachDaniel•3y ago
Hmm...something must be wrong with the automated releases or something then. we'll address that soon for now I'd suggest just staying on the main branch
vedha.ivan
vedha.ivanOP•3y ago
ohh ok the failure html is not working tough
ZachDaniel
ZachDaniel•3y ago
not working in what way?
vedha.ivan
vedha.ivanOP•3y ago
if i enter a wrong password on the sign in page, i get this page
vedha.ivan
vedha.ivanOP•3y ago
No description
ZachDaniel
ZachDaniel•3y ago
🤔 not sure whats going on there, but it must be something wrong with the phoenix set up although, FWIW, you probably don't want that failure.html page anyway Typically what people will do is just redirect back to sign in with a flash message
vedha.ivan
vedha.ivanOP•3y ago
i understand, i will try to adjust to that behavior maybe tomorrow ill start over just to see if it was something on the config step i missed thank you Zach have a great day

Did you find this page helpful?