skip to Main Content

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

2

Answers


  1. 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:

    Login or Signup to reply.
  2. Reason login page is rendered even logged in is because login page rendering request is not sent to the server.
    In the login form submission, you can put additional option to replace the page.
    Browser back button will also replace the page and eventually, rendering request gets sent.

    Inertia.post('/login', {
       email: email, 
       password: password 
    }, {
       replace: true 
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search