skip to Main Content

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


  1. Chosen as BEST ANSWER

    I "solved" this problem (probably permanently) by overriding the login method instead of the authenticate method. Even tho the documentation specifically talks about the authenticate 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 the authenticate.


  2. 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,

    1. Your laravel version is 10 or something other than 10? Use the following command,

      php artisan –version

    2. 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,

    app/Http/Controllers/Auth/AuthenticatedSessionController.php

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search