Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix exception with multi guard auth & filament multipanel #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bogusbd
Copy link

@bogusbd bogusbd commented Dec 7, 2023

FIX TypeError

Filament\FilamentManager::getUserName(): Argument #1 ($user) must be of type Illuminate\Database\Eloquent\Model|Illuminate\Contracts\Auth\Authenticatable, null given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 355

The error can be reproduced as follows:

  1. Create 2 guards /config/auth.php
    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'company' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
    ],
  1. One panel uses the default guard. Second custom, like this
    public function panel(Panel $panel): Panel
    {
        return $panel
           // ......
            ->path('company')
            ->authGuard('company')
            // ......
            ;
    }
  1. From default guards try to impersonate.
    public static function table(Table $table): Table
    {
        return $table
             // .....
            ->actions([
                Impersonate::make('Login as')->guard('company')->redirectTo('/company/'),
            ])
    }
  1. Open the URL for the default guard ... and you will see an Exception

Perhaps this can be fixed through the config /config/filament-impersonate.php but I'm not sure.

@jszobody
Copy link
Member

@bogusbd It looks like you're making this fall back to empty string. Is that really the best option?

I don't have any multi-panel apps like this, but it seems like you'd still want the accurate user name to be displayed. Is it possible instead to pull the current user from the correct Filament authGuard?

Since you specify guard('company') perhaps we need to look at making sure the banner uses this guard when retrieving the user. I haven't dug into it yet. Does that seem reasonable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants