pwangdu786

pwangdu786

Hello there,
I am new to Elixir and Phoenix and so far loving it. I am trying the phx_gen_auth library and i am getting the following error.

no route found for GET /users/log_out (TeacherWeb.Router)

I ran the mix phx.routes command and can see the /users/log_out route available. Please see the results below.

Available routes

           page_path  GET     /                                     TeacherWeb.PageController :index
           post_path  GET     /posts                                TeacherWeb.PostController :index
           post_path  GET     /posts/:id/show                       TeacherWeb.PostController :show
 live_dashboard_path  GET     /dashboard                            Phoenix.LiveView.Plug :home
 live_dashboard_path  GET     /dashboard/:page                      Phoenix.LiveView.Plug :page
 live_dashboard_path  GET     /dashboard/:node/:page                Phoenix.LiveView.Plug :page

user_registration_path GET /users/register TeacherWeb.UserRegistrationController :new
user_registration_path POST /users/register TeacherWeb.UserRegistrationController :create
user_session_path GET /users/log_in TeacherWeb.UserSessionController :new
user_session_path POST /users/log_in TeacherWeb.UserSessionController :create
user_reset_password_path GET /users/reset_password TeacherWeb.UserResetPasswordController :new
user_reset_password_path POST /users/reset_password TeacherWeb.UserResetPasswordController :create
user_reset_password_path GET /users/reset_password/:token TeacherWeb.UserResetPasswordController :edit
user_reset_password_path PUT /users/reset_password/:token TeacherWeb.UserResetPasswordController :update
feed_path GET /feeds TeacherWeb.FeedController :index
user_settings_path GET /users/settings TeacherWeb.UserSettingsController :edit
user_settings_path PUT /users/settings TeacherWeb.UserSettingsController :update
user_settings_path GET /users/settings/confirm_email/:token TeacherWeb.UserSettingsController :confirm_email
user_session_path DELETE /users/log_out TeacherWeb.UserSessionController :delete
user_confirmation_path GET /users/confirm TeacherWeb.UserConfirmationController :new
user_confirmation_path POST /users/confirm TeacherWeb.UserConfirmationController :create
user_confirmation_path GET /users/confirm/:token TeacherWeb.UserConfirmationController :confirm

I am not sure what I am doing wrong.

Please help.

Showing Posts 1 to 10

sezaru

sezaru

You don’t have a route to GET /usesr/log_out, you have a route to DELETE /users/log_out, just change your HTTP request from GET to DELETE and it should work.

hubertlepicki

hubertlepicki

Or, explicitly add such route.

I find it useful to have GET /logout or similar especially for single page apps or apps that break in general, or just in case something breaks and having GET /logout allows user to just go to this URL and basically nuke their session and start over…

pwangdu786

pwangdu786 OP

Thank you @sezaru. That worked.

julismz

julismz

delete method is ok and according to standars. The problem probably is that you are not including the app.js located on /assets/js

Make sure you have these lines on your template:

<link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/assets/app.css")}/>
    <script defer phx-track-static type="text/javascript" src={Routes.static_path(@conn, "/assets/app.js")}></script>
hubertlepicki

hubertlepicki

or there’s an erro in that JS file somewhere and it doesn’t install the hooks needed to make delete route work. I usually add GET to logout path just for that very case, people have weird things also like ad blockers being too greedy etc. where they accidentally break themselves JS and then can’t log out of app or there’s a weird condition for that particular user resulting in a JS crashing…

LostKobrakai

LostKobrakai

You could also inline the form usually created on demand by JS. No need for the JS then, but still get the proper route called.

gcb

gcb

Or you have non-js users…

julismz

julismz

from my point of view, non-js users don’t deserve the right of internet navigation, not even my time to think or program special stuff for them, and I’m being polite…

hubertlepicki

hubertlepicki

Let me tell you what will happen at some point.

You will mess up. Or someone else will. Maybe a third-party library. You’ll end up with cookies exceeding the limit that your server, or load balancer will handle. Or there will be another issue that is easily fixable by giving the user log out link. Your JS may crash and DELETE /logout won’t work. I mentioned it above in 2021, and it probably happened to me once or twice since.

Even if that’s not your primary way of calling logout, maybe even keep the DELETE route but also do GET one to log users out. It has no downsides to do so and can save you a lot of trouble.

julismz

julismz

That is a good point, I’ll take it :ok_hand:

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews