I followed the documentation and overrode the Authenticate method: https://laravel.com/docs/10.x/authentication#authenticating-users
However, it still doesn’t run. I mean my custom code is not run when the user logs in.
I copy-pasted the entire code block from the documentation and just added a Log::info into it, so if it ran, I’d see "Hello from authenticate" in the logs file, but I see nothing. I also deleted everything from it and just left the Log in it, yet I get authenticated without an issue.
What did I miss?
HTTP->Controllers->Auth->LoginController: authenticate — Using only the code below, the user still gets authenticated without a problem. But they shouldn’t.
public function authenticate(Request $request): RedirectResponse
{
Log::info("Authenticate is started");
return back()->withErrors([ // this is a default response if an error occured.
'email' => 'Just testing.',
])->onlyInput('email');
}
Edit: I did optimize:clear and composer du too, nothing changed.
2
Answers
I "solved" this problem (probably permanently) by overriding the
login
method instead of theauthenticate
method. Even tho the documentation specifically talks about theauthenticate
method, seems like it's never called in the login, nor the register methods, so it's just floating around.I'll give room to people who might know an answer why - or to correct me if I'm wrong, but until then, that's that: override the
login
instead of theauthenticate
.Hey it looks like you’re referring Laravel 10 documentation but implementing different version of laravel instead of 10. SO the following thing you should first check,
Your laravel version is 10 or something other than 10? Use the following command,
php artisan –version
Check if the controller you’re looking for is the same which is being used for the authentication. Now if you’re using laravel 10 then you should look into the following controller,