framework: When ValidationException is thrown, user is redirected to /

  • Laravel Version: 5.7.19
  • PHP Version: 7.2.13
  • Database Driver & Version: PostgreSQL 11.1

Description:

When LoginController (Illuminate\Foundation\Auth\AuthenticatesUsers) throws new ValidationException user is redirected to /. I tried to debug the issue myself and found out that the ValidationExcpetion the controller throws has attribute redirectTo set to null. If I change this attribute to /login it redirects successfully. I don’t know the inner workings of Laravel that well, so this may not be the thing that causes the issue. However any help will be appreciated.

Steps To Reproduce:

  1. Create a new Laravel app an set up your environment
  2. Do php artisan make:auth
  3. Go to /login and input some invalid data
  4. It should redirect you to /

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 27 (21 by maintainers)

Most upvoted comments

This might help others who have this issue.

I had the same issue in Laravel 8: When on /login and entering wrong login credentials it redirected to the / instead of back to /login. I can confirm this “bug” is not present in a fresh Laravel 8 project.

But, I found that the underlying problem was that url()->previous() always returned the root url. Behind the scene url()->previous() will read from the referrer header, and that’s where my problem was.

This HTML meta tag was present in my blade and caused the referrer header to always be the root url: <meta name="referrer" content="strict-origin" />

Removing this HTML meta tag solved the problem! Or replace with: <meta name="referrer" content="origin-when-cross-origin" />

@sebsobseb Thank you so much! This helped me immensely! It’s been months that I’ve been hearing of this bug and I couldn’t track it down. Thank you a thousand times over (and from my users too)!

Okay, I am sorry I bothered everyone with this issue. Just now, I got an idea, whether it could be caused by the browser. So I opened the site in another browser and it worked. Probably some add-on is misbehaving or my tinkering with Firefox’s about:config has broke something. Anyways, thanks for the help.

I realize a lot of people have already tried helping you here but can you please try one of the below support channels instead? This issue tracker isn’t meant to be used to get support with an application related problem. I also highly doubt this is an issue with the framework itself.

Sounds like sessions may not be working correctly. If you login successfully, then refresh the page, do you stay logged in?