F
Filament11mo ago
hdaklue

Make all panels use the same Login and Logout routes.

any idea? the issue that I can't find away to override this function public function getLoginUrl(array $parameters = []): ?string { if (! $this->hasLogin()) { return null; } return route("filament.{$this->getId()}.auth.login", $parameters); }
3 Replies
code jam
code jam11mo ago
They use the same login / logout routes for all panels. Only the theming would be different. Replace $this->getId() to the panel whose login screen you want to display for all panels. E.g. if you want to use admin panel login for all panels, replace the route as filament.admin.auth.login
Andrew Wallo
Andrew Wallo11mo ago
@hassan.ib I would instead do the following. For each of your panels, create a middleware. I will use the default Laravel Authenticate middleware for this example. In App\Http\Middleware\Authenticate do the following:
namespace App\Http\Middleware;

use Filament\Facades\Filament;
use Filament\Http\Middleware\Authenticate as Middleware;

class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*/
protected function redirectTo($request): ?string
{
return Filament::getDefaultPanel()->getLoginUrl();
}
}
namespace App\Http\Middleware;

use Filament\Facades\Filament;
use Filament\Http\Middleware\Authenticate as Middleware;

class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*/
protected function redirectTo($request): ?string
{
return Filament::getDefaultPanel()->getLoginUrl();
}
}
In all of your panels, replace the Auth Middleware with the one I just showed you:
->authMiddleware([
\App\Http\Middleware\Authenticate::class;
]);
->authMiddleware([
\App\Http\Middleware\Authenticate::class;
]);
Then in the panel which has the Login you want for all panels, just do the following:
public function panel(Panel $panel): Panel
{
return $panel
->default()
}
public function panel(Panel $panel): Panel
{
return $panel
->default()
}
Make sure that no other panels are assigned as the default.
hdaklue
hdaklue10mo ago
@Andrew Wallo thanks a lot, I did something similar.