I'm using Fortify with Laravel 11, and I'm looking to extend Fortify to allow me to perform an action when a user successfully logs in.
In a nutshell, when the user has logged in, I want to store a couple of additional session variables before the user is then redirected to the dashboard. Is there a method I can call in the FortifyServiceProvider's register or boot methods to achieve this or is there another/ better way of doing this?
You could just replace the LoginResponse with your own that stores the session variables.
Something like:
// FortifyServiceProvider
public function register(): void
{
$this->app->instance(LoginResponse::class, new class implements LoginResponse {
public function toResponse($request)
{
// Store session variables here
return $request->wantsJson()
? response()->json(['two_factor' => false])
: redirect()->intended(Fortify::redirects('login'));
}
});
}