Fixed redirect after login for filament admin panel

This commit is contained in:
Constantin Graf
2024-05-01 21:40:29 +02:00
parent c3010c7f62
commit f989a06dc8
2 changed files with 31 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace App\Extensions\Fortify;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Laravel\Fortify\Http\Responses\LoginResponse;
use Symfony\Component\HttpFoundation\Response;
class CustomLoginResponse extends LoginResponse
{
/**
* Create an HTTP response that represents the object.
*
* @param Request $request
*/
public function toResponse($request): Response
{
$redirectPath = session()->pull('url.intended', route('dashboard', [], false));
return $request->wantsJson()
? response()->json(['two_factor' => false])
: Inertia::location($redirectPath);
}
}

View File

@@ -8,6 +8,7 @@ use App\Actions\Fortify\CreateNewUser;
use App\Actions\Fortify\ResetUserPassword;
use App\Actions\Fortify\UpdateUserPassword;
use App\Actions\Fortify\UpdateUserProfileInformation;
use App\Extensions\Fortify\CustomLoginResponse;
use App\Models\User;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
@@ -16,6 +17,7 @@ use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\Http\Responses\LoginResponse;
class FortifyServiceProvider extends ServiceProvider
{
@@ -60,5 +62,7 @@ class FortifyServiceProvider extends ServiceProvider
RateLimiter::for('two-factor', function (Request $request) {
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});
$this->app->instance(LoginResponse::class, new CustomLoginResponse());
}
}