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.
php artisan make:auth/login and input some invalid data/can you give me an example of an invalid data? All I got is 'These credentials do not match our records.'
Following the provided steps, I'm redirected back to the login page with the message "credentials don't match".
Okay, I just did laravel new test, set up testing PostgreSQL database, did artisan make:auth and serve. I opened the browser to login page, entered some dummy data, and it redirected me to homepage.
In Illuminate\Foundation\Auth\AuthenticatesUsers in login() it fails at line 53, where it returns the failed login response. The function sendFailedLoginResponse() calls ValidationException::withMessages(), this creates the following ValidationException instance.
ValidationException {#246 â–¼
+validator: Validator {#242 â–¶}
+response: null
+status: 422
+errorBag: "default"
+redirectTo: null
#message: "The given data was invalid."
#code: 0
#file: "/tmp/test/vendor/laravel/framework/src/Illuminate/Validation/ValidationException.php"
#line: 71
trace: {â–¶}
}
However as you can see the attribute redirectTo is null. I suspect this might be the issue, but I am not sure. This instance then gets thrown and the user is redirect to the homepage (localhost:8000/).
I installed Laravel Telescope to see what's going on. This is the screenshot of the /login POST request.
I also installed laravel-debugbar. Which upon me being redirect to homepage tells me that the /login POST reuqest (shown as stacked) gave one exception.
The given data was invalid./tmp/test/vendor/laravel/framework/src/Illuminate/Validation/ValidationException.php#71
*/
public static function withMessages(array $messages)
{
return new static(tap(ValidatorFacade::make([], []), function ($validator) use ($messages) {
foreach ($messages as $key => $value) {
foreach (Arr::wrap($value) as $message) {
$validator->errors()->add($key, $message);
This is all the data I managed to obtain by debugging. Hopefully this is helpful. Also here is an output of php -i, maybe it can also prove to be helpful
Okay I checked other projects I have written in Laravel and they all share the same issue, no matter the Laravel version. So probably an issue with my PHP config I guess.
I don't really understand what you really want. I confused about step 4 of "Steps To Reproduce":
Anyway, the ValidationException is handled by Illuminate\Foundation\Exceptions\Handler:
/**
* Convert a validation exception into a response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Validation\ValidationException $exception
* @return \Illuminate\Http\Response
*/
protected function invalid($request, ValidationException $exception)
{
return redirect($exception->redirectTo ?? url()->previous())
->withInput($request->except($this->dontFlash))
->withErrors($exception->errors(), $exception->errorBag);
}
So I am on a /login page. It shows the login page as expected. It can log me in, no problem with that. However, the problem occurs when I input invalid data, e.g. it has to throw a ValidationException.
The expected result is that it redirects you back to the /login page and shows you the errors, the exception messages.
My results are that instead I am redirected to / page, the root, no matter from where the ValidationException is thrown. So this applies to /login, /register, and anything that implements the ValidationException.
Did this explanation make it clear?
Maybe the issue on this line in the Handler:
return redirect($exception->redirectTo ?? url()->previous())
I used dd(url()->previous()) to see what does Laravel think my previous route is and it turns out, the output is my root url: "http://project.test/".
Has anybody ever encountered this?
Sounds like sessions may not be working correctly. If you login successfully, then refresh the page, do you stay logged in?
Yes, I stay logged in.
Can you push a project to github that has this issue, so we can check it out?
Well as I mentioned earlier, the problem seems to be rather odd, as I experience this issue across all my Laravel projects. Thus, I think the problem is not in the Laravel framework itself. Possibly it is something to do with my PHP configuration, or I don't know what else could be causing this.
I have no idea. I haven't ever got the same issue before. This feature works normally for me.
You should make Steps To Reproduce section such as:
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
## Expected
- The application redirects the user back to login with errors.
## Actual
- The application redirects the user to the home page. (that means the user has been loged in successfully).
May any others help you?
No as the user is redirected to the home page without being logged in successfuly
Well, I don't think this issue is raised by the core Framework. All my Laravel projects work normally. I have no idea.
Unable to replicate using same PHP version. Displays the proper validation message within /login. It seems as if you have a bunch of extra packages that aren't mentioned in your original post that may cause some redirects. (nova, etc)
Were you able to create a _fresh_ Laravel installation and follow the steps to reach this issue?
Okay I did:
laravel new projectphp artisan make:authphp artisan servelocalhost:8000 and went to /login[email protected] and password to the login page (invalid data)localhost:8000/ e.g. the rootI also tried uninstalling my PHP, removing all the config files, installing a fresh copy of the newest PHP (7.3.0), but still it doesn't work for some unknown. reason.
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.
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.