How do I redirect a user after login based on the panel they are allowed to view?

I have 2 panels:
class CpPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('cp')
->path('cp')
//...
class CpPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('cp')
->path('cp')
//...
class FrontendPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->id('frontend')
->path('')
class FrontendPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->id('frontend')
->path('')
I want to say, if you can view the Cp then redirect there, else redirect to the frontend. I have this in app/Http/Responses/LoginResponse.php
class LoginResponse implements LoginResponseContract
{
public function toResponse($request)
{
return auth()->user()->canAccessPanel('TODO') ? 'TODO' : 'TODO';
}
}
class LoginResponse implements LoginResponseContract
{
public function toResponse($request)
{
return auth()->user()->canAccessPanel('TODO') ? 'TODO' : 'TODO';
}
}
Solution:
Gone with this, which is okay at the moment:
```php return Auth::user()->canAccessPanel(Filament::getPanel('cp')) ? redirect()->intended(route('filament.cp.pages.dashboard')) : redirect()->intended(route('home'));...
Jump to solution
4 Replies
Solution
johncarter
johncarter16mo ago
Gone with this, which is okay at the moment:
return Auth::user()->canAccessPanel(Filament::getPanel('cp'))
? redirect()->intended(route('filament.cp.pages.dashboard'))
: redirect()->intended(route('home'));
return Auth::user()->canAccessPanel(Filament::getPanel('cp'))
? redirect()->intended(route('filament.cp.pages.dashboard'))
: redirect()->intended(route('home'));
JDMhammer
JDMhammer12mo ago
@johncarter how did you implement the response into a panel?
awcodes
awcodes12mo ago
Wouldn’t this be better in a middleware?
JDMhammer
JDMhammer12mo ago
I ended up moving the navigation item to the page header as that was causing it to redirect to an unintended location. Seemed like the simpler change 🤷‍♂️
Want results from more Discord servers?
Add your server