It seems that you should return the user or null. This is neither
return back()->withNotify($notify)->withInput();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to customize the authorization by using the following in FortifyServiceProvider.php
Fortify::authenticateUsing(function (Request $request) {
$user = User::where('username', $request->username)->first();
$request->validate([
'captcha' => 'required|numeric|digits:6',
'username' => 'required|string',
'password' => 'required|string',
]);
if (isset($request->captcha)) {
if (!captchaVerify($request->captcha, $request->captcha_secret)) {
$notify[] = ['error', "Invalid Captcha"];
return back()->withNotify($notify)->withInput();
}
}
if ($user && Hash::check($request->password, $user->password)) {
return $user;
}
});
but it gives the following exception Illuminate\Auth\SessionGuard::login(): Argument 1 ($user) must be of type Illuminate\Contracts\Auth\Authenticatable, Illuminate\Http\RedirectResponse given, called in C:\wamp\www\core\vendor\laravel\fortify\src\Actions\AttemptToAuthenticate.php on line 80.
I have tried to comment the PrepareAuthenticatedSession::class in the following authenticateThrough
Fortify::authenticateThrough(function (Request $request) {
return array_filter([
config('fortify.limiters.login') ? null : EnsureLoginIsNotThrottled::class,
Features::enabled(Features::twoFactorAuthentication()) ? RedirectIfTwoFactorAuthenticatable::class : null,
// AttemptToAuthenticate::class,
PrepareAuthenticatedSession::class,
]);
});
it works without the mentioned error, but the user even if he disables two-factor authentication will not be able to log in.
Any idea for how to fix the problem or even an explanation of this exception could also be useful!
@nbukhari you still have the redirect. Can you try and remove it like this?
if (!captchaVerify($request->captcha, $request->captcha_secret)) {
return null;
}
Please or to participate in this conversation.