Two panels with two auth guards, logges me out from both

I have two panels: admin and partner. First is using the web guard, second the partner guard (see config/auth.php):
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'partner' => [
'driver' => 'session',
'provider' => 'users',
],
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'partner' => [
'driver' => 'session',
'provider' => 'users',
],
],
$panel->path("admin")->authGuard("web")
...
$panel->path("partner")->authGuard("partner")
$panel->path("admin")->authGuard("web")
...
$panel->path("partner")->authGuard("partner")
It works. When navigating to /admin I can login as admin, and when going to /partner I can login as a partner. Now I am logged in as 2 different users as expected. But when I click on logout on one of the panel, I am logged out in the other panels as well. That makes no sense? When putting on of the panels on a (sub-)domain, then it works as well, but when I log out from one, I stay logged in in the other panel (this is the expected behaviour IMHO).
7 Replies
vitsw
vitsw14mo ago
Hello, did you find the solution? I have the same issue.
bernhard
bernhardOP14mo ago
@vitsw Sorry for late reply. I didn't find a solution, so I moved the panels on different subdomains. Not pretty, not optimal, not what i wanted, but it works
bernhard
bernhardOP13mo ago
GitHub
Logout button logs out from all panels, not just the current (authg...
Package filament/filament Package Version v3.0.89 Laravel Version v10.30.1 Livewire Version No response PHP Version 8.1.25 Problem description When creating 2 panels, which both have their own auth...
Sourabh
Sourabh10mo ago
Hi , I have the same issue .if you get any solution so please share it . I have found a solution for this. Create a LogoutController inside "app/Overrides/LogoutController.php" and paste the code .
php
class LogoutController
{
public function __invoke(Request $request): LogoutResponse
{
$panel = Filament::getCurrentPanel();
Filament::auth()->logout();
switch ($panel->getId()) {
case 'app':
$request->session()->forget('guard.web');
break;
case 'admin':
$request->session()->forget('guard.admin');
break;
}
$request->session()->regenerateToken();
return app(LogoutResponse::class);
}
}
php
class LogoutController
{
public function __invoke(Request $request): LogoutResponse
{
$panel = Filament::getCurrentPanel();
Filament::auth()->logout();
switch ($panel->getId()) {
case 'app':
$request->session()->forget('guard.web');
break;
case 'admin':
$request->session()->forget('guard.admin');
break;
}
$request->session()->regenerateToken();
return app(LogoutResponse::class);
}
}
update composer.json file . and run composer dump-autoload.
"autoload": {
"exclude-from-classmap": [
"vendor/filament/filament/src/Http/Controllers/Auth/LogoutController.php"
],
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
},
"files": [
"app/Overrides/LogoutController.php"
]
},
"autoload": {
"exclude-from-classmap": [
"vendor/filament/filament/src/Http/Controllers/Auth/LogoutController.php"
],
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
},
"files": [
"app/Overrides/LogoutController.php"
]
},
bernhard
bernhardOP10mo ago
That would be a great article for https://filamentphp.com/community
Filament
Articles - Filament
A collection of articles written by the Filament team and our community.
undercode
undercode10mo ago
Thank you, @Sourabh Unfortunately your approach didn't work for me. Instead, I had to remove your composer.json modifications and add an alias to the default LoginController in my AppServiceProvider, as follows:
use Filament\Http\Controllers\Auth\LogoutController;
use App\Overrides\LogoutController as NewLogoutController;

public function register(): void
{
$loader = AliasLoader::getInstance();
$loader->alias(LogoutController::class, NewLogoutController::class);
}
use Filament\Http\Controllers\Auth\LogoutController;
use App\Overrides\LogoutController as NewLogoutController;

public function register(): void
{
$loader = AliasLoader::getInstance();
$loader->alias(LogoutController::class, NewLogoutController::class);
}
And I made some modifications to your LogoutController to keep it simpler and without the need to know the name of the panels and their guards:
<?php

namespace App\Overrides;

use Filament\Facades\Filament;
use Filament\Http\Responses\Auth\Contracts\LogoutResponse;
use Illuminate\Http\Request;

class LogoutController
{
public function __invoke(Request $request): LogoutResponse
{
$panel = Filament::getCurrentPanel();
Filament::auth()->logout();
$request->session()->forget($panel->getAuthGuard());
$request->session()->regenerateToken();

return app(LogoutResponse::class);
}
}
<?php

namespace App\Overrides;

use Filament\Facades\Filament;
use Filament\Http\Responses\Auth\Contracts\LogoutResponse;
use Illuminate\Http\Request;

class LogoutController
{
public function __invoke(Request $request): LogoutResponse
{
$panel = Filament::getCurrentPanel();
Filament::auth()->logout();
$request->session()->forget($panel->getAuthGuard());
$request->session()->regenerateToken();

return app(LogoutResponse::class);
}
}
Majid Al Zariey
Majid Al Zariey3mo ago
I believe this is a candidate for a pull request Might be because of https://discordapp.com/channels/883083792112300104/883085267383226478/935484862788407336
Want results from more Discord servers?
Add your server