#Multiple Panels, 1 Login Screen

6 messages · Page 1 of 1 (latest)

ornate totem
#

Hi, I am building filament v3 app that has multiple panels.

Instead of having different login urls, i want to have 1 login url, and based on the user_type (stored in the users table) it needs to redirect to the correct panel.

I tried creating a seperate panel, which seems to kind of work, but I cant get the redirection to work. Anyone that can push me into the right direction? Or is there a better practice?

I tried overriding the LoginResponse with a custom one. But also doesnt seem to work.

gusty terraceBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

hexed sphinx
#

I would like to know also 😎

still pagoda
#

@ornate totem @hexed sphinx

I have a setup like this, and use below code.
Don't think it is the best code solution, but it works for me till i see a better method for doing this.

Helper Function

public static function getPanelDashboardUrlFromUser()
{
    if (Filament::auth()->check()) {

        $user = Filament::auth()->user();

        $panelAdmin = Filament::getPanel('admin');
        $panelOther = Filament::getPanel('other');

        if ($user->canAccessPanel($panelAdmin)) {
            return route('filament.admin.pages.dashboard');
        } elseif ($user->canAccessPanel($panelOther)) {
            return route('filament.other.pages.dashboard');
        } else {
            return null;
        }
    }

    return null;
}

Default Panel (also login panel)

return $panel
        ->id('main')
        ->path('app')
        ->login()

Other Panel.

return $panel
        ->id('other')
        ->path('other')
        ->login(fn () => redirect(Filament::getPanel('main')->login()->getUrl()))

Admin Panel.

return $panel
        ->id('admin')
        ->path('admin')
        ->login(fn () => redirect(Filament::getPanel('main')->login()->getUrl()))

Class LoginResponse

class LoginResponse implements Responsable
{
    public function toResponse($request): RedirectResponse|Redirector
    {
        $panelRedirct = Helpers::getPanelDashboardUrlFromUser();
        if ($panelRedirct != null) {
            return redirect()->to($panelRedirct);
        }

        return redirect()->intended(Filament::getUrl());
    }
}

Main Route

Route::get('/', function () {

    if (Filament::auth()->check()) {
        $panelRedirct = Helpers::getPanelDashboardUrlFromUser();
        if ($panelRedirct != null) {
            return redirect()->to($panelRedirct);
        }
    }

    return redirect('app');
});
hexed sphinx
#

Top! @still pagoda

still pagoda
#

And the logic for your own canAccessPanel in de model.
I know it works with Tenacy on the main panel, dont know if this works if you have tenacy on the other panels.
Als if you have acces to multiple panels, i use the plugin https://filamentphp.com/plugins/bezhansalleh-panel-switch to add a button so you can switch between them without changing the url.