From 97751b349984d88c0fc3f78d99da5e83aad1f7d9 Mon Sep 17 00:00:00 2001 From: Constantin Graf Date: Thu, 2 May 2024 16:20:52 +0200 Subject: [PATCH] Fixed redirect after two factor login for filament admin panel --- .../Fortify/CustomTwoFactorLoginResponse.php | 28 +++++++++++++++++++ app/Providers/FortifyServiceProvider.php | 3 ++ config/app.php | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 app/Extensions/Fortify/CustomTwoFactorLoginResponse.php diff --git a/app/Extensions/Fortify/CustomTwoFactorLoginResponse.php b/app/Extensions/Fortify/CustomTwoFactorLoginResponse.php new file mode 100644 index 00000000..9f3ae6a3 --- /dev/null +++ b/app/Extensions/Fortify/CustomTwoFactorLoginResponse.php @@ -0,0 +1,28 @@ +pull('url.intended', route('dashboard', [], false)); + + return $request->wantsJson() + ? new JsonResponse('', 204) + : Inertia::location($redirectPath); + } +} diff --git a/app/Providers/FortifyServiceProvider.php b/app/Providers/FortifyServiceProvider.php index 4dbe82d4..1eaabb34 100644 --- a/app/Providers/FortifyServiceProvider.php +++ b/app/Providers/FortifyServiceProvider.php @@ -9,6 +9,7 @@ use App\Actions\Fortify\ResetUserPassword; use App\Actions\Fortify\UpdateUserPassword; use App\Actions\Fortify\UpdateUserProfileInformation; use App\Extensions\Fortify\CustomLoginResponse; +use App\Extensions\Fortify\CustomTwoFactorLoginResponse; use App\Models\User; use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Http\Request; @@ -16,6 +17,7 @@ use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; +use Laravel\Fortify\Contracts\TwoFactorLoginResponse; use Laravel\Fortify\Fortify; use Laravel\Fortify\Http\Responses\LoginResponse; @@ -64,5 +66,6 @@ class FortifyServiceProvider extends ServiceProvider }); $this->app->instance(LoginResponse::class, new CustomLoginResponse()); + $this->app->instance(TwoFactorLoginResponse::class, new CustomTwoFactorLoginResponse()); } } diff --git a/config/app.php b/config/app.php index d05bf660..d3e3d449 100644 --- a/config/app.php +++ b/config/app.php @@ -18,7 +18,7 @@ return [ | */ - 'name' => env('APP_NAME', 'Laravel'), + 'name' => env('APP_NAME', 'solidtime'), /* |--------------------------------------------------------------------------