I am trying to change the page the user is sent to after logging out from the route directory to a login page. I'm using inertia vue. I thought this would be as simple as just changing a value but no matter how much I google I can't find anyone else struggling with this. I was hoping someone here might have some valuable insights on this?
#How do I change Inertias logout route?
1 messages Β· Page 1 of 1 (latest)
Inertia itself doesn't have anything to do with logout. You will have to find out the controller responsible for this. It could be Jetstream, Breeze, Laravel UI or something else.
run this in the console to find out where the controller is:
php artisan route:list --name=logout
I ended up making a logout controller and sending the logout request and a redirect from there. Fyi it does appear that inertia handles the logout request to some degree in my situation π
Fyi it does appear that inertia handles the logout request to some degree in my situation π
It doesn't tho..? Inertia doesn't do anything regarding authentication, it doesn't register routes, in essence it's just a protocol / routing library like Vue Router
I haven't been coding for too long so sorry for my inexperience but my controller looks like this which seems to rely on inertia class LogoutController extends Controller
{
/**
* Log out account user.
*
* @return \Illuminate\Routing\Redirector
*/
public function index()
{
Session::flush();
Inertia::render('/user/logout');
return redirect('/user/login');
}
}
Just calling Inertia::render('/user/logout'); has no effect π
You made an Inertia response, then promptly discarded it and made a redirect one, which was returned to the browser.
I understand what I did, and calling Inertia::render('/user/logout'); logs out the user it does not do nothing π
Whether inertia itself logs out the user I frankly do not know as I said I'm new to this, but it's used to a degree in my solution
Session::flush() is what functionally does it, in the most wrong way possible.
That does nothing, it creates a response, just like response()->json() would, it doesn't lot out the user
Then tell me the right way to do it. In the nicest way possible this all could have been done in like two messages if yall gave better answers
Like I greatly appreciate the help but yall are just saying 'no' and 'wrong' without telling me how I should ne doing it
Sorry, meant to. Got told to head home and forgot.
Auth::logout() properly does everything Laravel expects.
Winter storms is all kinds of fun.
Thanks when I got to the problem they were using a inertia route in js in a vue file for their logout
Well now I'm back to it not redirecting to the login page π
See the Laravel docs on properly invalidating the session and redirecting the user somewhere afterwards; https://laravel.com/docs/10.x/authentication#logging-out
Can I ask why this is wrong because I am having a hard time redirecting the proper way π
Because this Flushes the whole session, which might.
Use something like this in your sessions / auth / login (whatever you called it) controller:
public function destroy()
{
auth()->logout();
return redirect('/login')->with('success', 'You have been logged out!');
}
May I suggest, when people told you that this is a Laravel thing and not an inertia thing, that next time you post a thread in the laravel discord?