Laravel Failed Login Event is not fired

I try to listen to login failures events, however, my listener is never called.

I registered the listener in the EventServiceProvider:

protected $listen = [
    'Illuminate\Auth\Events\Login' => [
        MyFailedLoginAttemptListener::class,
    ],
    Registered::class              => [
        SendEmailVerificationNotification::class,
    ],
];

But when a user fails to login my listener is not called

public function handle( Login $event ) {
        var_dump( $event );
        exit;
    }
}

What is wrong, I've spent a lot of time trying to debug this issue.

Thank you.

1 answer

  • answered 2019-06-25 05:56 CROSP

    It seems that you are not listening to the event you want :)

    In order to be notified about failed login attempts, you need to listen to the Failed event from the same namespace.

    So in your case, you should refactor your code in the following way:

    protected $listen = [
        'Illuminate\Auth\Events\Failed' => [
            MyFailedLoginAttemptListener::class,
        ],
        Registered::class              => [
            SendEmailVerificationNotification::class,
        ],
    ];
    

    And of course, change the event argument type hinting:

    public function handle( Failed $event ) {
            var_dump( $event );
            exit;
        }
    }
    

    Hope this will eliminate the problem.