diff --git a/web/Modules/Customer/App/Http/Middleware/CustomerAuthenticate.php b/web/Modules/Customer/App/Http/Middleware/CustomerAuthenticate.php new file mode 100644 index 0000000..068db98 --- /dev/null +++ b/web/Modules/Customer/App/Http/Middleware/CustomerAuthenticate.php @@ -0,0 +1,38 @@ + $guards + */ + protected function authenticate($request, array $guards): void + { + $guard = Filament::auth(); + + if (! $guard->check()) { + $this->unauthenticated($request, $guards); + + return; + } + + $this->auth->shouldUse(Filament::getAuthGuard()); + +// /** @var Model $user */ +// $user = $guard->user(); +// +// $panel = Filament::getCurrentPanel(); + + } + + protected function redirectTo($request): ?string + { + return Filament::getLoginUrl(); + } +} diff --git a/web/Modules/Customer/App/Providers/Filament/CustomerPanelProvider.php b/web/Modules/Customer/App/Providers/Filament/CustomerPanelProvider.php index 4a368c5..641fbf7 100644 --- a/web/Modules/Customer/App/Providers/Filament/CustomerPanelProvider.php +++ b/web/Modules/Customer/App/Providers/Filament/CustomerPanelProvider.php @@ -75,7 +75,7 @@ class CustomerPanelProvider extends PanelProvider ]) ->authGuard('web_customer') ->authMiddleware([ - Authenticate::class, + CustomerAuthenticate::class, ]); } diff --git a/web/app/Models/HostingSubscriptionBackup.php b/web/app/Models/HostingSubscriptionBackup.php index a7e1b2a..33d5f3e 100644 --- a/web/app/Models/HostingSubscriptionBackup.php +++ b/web/app/Models/HostingSubscriptionBackup.php @@ -37,16 +37,16 @@ class HostingSubscriptionBackup extends Model 'status' => BackupStatus::class, ]; -// protected static function booted(): void -// { -// static::addGlobalScope('customer', function (Builder $query) { -// if (auth()->check() && auth()->guard()->name == 'web_customer') { -// $query->whereHas('hostingSubscription', function ($query) { -// $query->where('customer_id', auth()->user()->id); -// }); -// } -// }); -// } + protected static function booted(): void + { + static::addGlobalScope('customer', function (Builder $query) { + if (auth()->check() && auth()->guard()->name == 'web_customer') { + $query->whereHas('hostingSubscription', function ($query) { + $query->where('customer_id', auth()->user()->id); + }); + } + }); + } public static function boot() { parent::boot();