Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
583 views
in Technique[技术] by (71.8m points)

php - Laravel 5.8 showing "419 Page Expired" after clicking logout from an already cleared session

I run the php artisan make:auth command and I will explain step by step what I do after that to understand the scenario,

  • Login to a new session (example.com/home)
  • opened a new tab and paste the url, ie example.com/home.
  • Now 2 tabs are open with the same session.
  • I clicked logout from one of the tab and it works perfectly fine
  • Then when I tried to logout from the other tab, it's giving me an error saying "419 Page Expired" and it is going nowhere even after reloading.

The thing is, these kind of scenarios may arise, and I don't want to see this error message, just logout after clicking logout, even if the session is expired.

Note: This issue is not because of not adding @csrf

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Well that's an obvious message you can maybe try to make a better layout for that page, but still it is good to show it so the user knows what happened. If you want to handle it differently you can try to redirect to the login page.

So in your appExceptionsHandler.php file within the render method add this:

if ($exception instanceof IlluminateSessionTokenMismatchException) {
    return redirect()->route('login');
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...