stechstudio / filament-impersonate

Filament plugin that makes it easy to impersonate your users
271 stars 55 forks source link

multipanel redirect #94

Closed njugunamwangi closed 2 months ago

njugunamwangi commented 2 months ago

My application has subdomains for every user role and on trying to redirect to a different panel i get a 403 Forbidden,

Here's how to reproduce the error

UserResource(Table Actions):

->actions([ Impersonate::make('impersonate') ->redirectTo(function($record) { switch (true) { case $record->hasRole(Role::DOCTOR): route('filament.doctor.pages.dashboard'); break;

                        case $record->hasRole(Role::LAB_TECH):
                            route('filament.laboratory.pages.dashboard');
                            break;

                    }
                }),

])

User.php (model)

class User extends Model implements FilamentUser {

public function canAccessPanel(Panel $panel): bool
{
    if ($panel->getId() == 'admin') {

        return $this->hasRole(Role::ADMIN);

    } elseif ($panel->getId() == 'doctor') {

        return $this->hasRole([
            Role::ADMIN,
            Role::DOCTOR,
        ]);

    } elseif ($panel->getId() == 'laboratory') {

        return $this->hasRole([
            Role::ADMIN,
            Role::LAB_TECH,
        ]);

    }
}

}

jszobody commented 2 months ago

First off, it doesn't look like your redirectTo callback is actually returning a value. Take a look at that.

Beyond that, you need to troubleshoot the 403 and see why it's failing. Do some debugging in your authorization policies or gates. There is not nearly enough information for me to see what the issue is, and it's likely to be something specific to your app, not a problem with this package.