Home > Software engineering >  how to prevent browser back to display login page after logged in in inertia js
how to prevent browser back to display login page after logged in in inertia js

Time:11-07

How to prevent browser back to display login page after logged in in inertia js? if you login to inertia demo CRM with this url :

Demo Inertia Js : https://demo.inertiajs.com/login

afetr loginning you can see login page by browser back again. How can I solve it? Thanks

CodePudding user response:

If you have successfully logged in and you go back using history back, the only thing you are doing is previewing how the login page looked like. You aren't doing any request, just visiting your browser's history.

If you go back and refresh the page, you can see that you are now being redirected to the dashboard, which means that you did a request and the server detected you are logged in. As you are logged in, redirects you from /login (guest) to /dashboard (auth).

So in my opinion there is nothing to solve, you don't need to prevent browser back to display login page, you need a middleware to redirect you out from guest routes if you are logged in, that is it.

Docs:

CodePudding user response:

@ericmp exactly my problem is base of first part of your answer, after successfully login when I go back using history back login page shows me again while everything is ok after refresh page. but I want browser history back redirect to dashboard when it happens and I couldn't find any solution in Inertia js!

  • Related