Breeze API / NextJS / Breeze - Setting up login 2FA
Hey Guys ... I have had to setup a 2FA implementation for a client a little different to 'standard' so I wasnt able to use Fortify.
I have a Laravel Breeze API / NextJS frontend stack .. I have added all the 2FA endpoints etc enabling and disabling through the logged in profile works just fine, and scanning the code in the mobile app works fine ... The last bit of the puzzle is to actually get it working with the login functionality which is what I cant figure out. I was having a look through the Fortify github repo and it seems i need to add some checks to the LoginRequest::authenticate method which comes with Breeze;
public function authenticate(): void
{
$this->ensureIsNotRateLimited();
// Check 2FA here
if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
RateLimiter::hit($this->throttleKey());
throw ValidationException::withMessages([
'email' => __('auth.failed'),
]);
}
RateLimiter::clear($this->throttleKey());
}
Which basically returns something like the following if 2FA is active;
return response()->json(['two_factor' => true])
Has anyone implemented this before without using Fortify? I cant seem to find any help
Please or to participate in this conversation.