Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobicloudvision committed May 12, 2024
1 parent 5a9cd63 commit 6b2263a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
38 changes: 38 additions & 0 deletions web/Modules/Customer/App/Http/Middleware/CustomerAuthenticate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Modules\Customer\App\Http\Middleware;

use Filament\Facades\Filament;
use Filament\Models\Contracts\FilamentUser;
use Illuminate\Auth\Middleware\Authenticate;
use Illuminate\Database\Eloquent\Model;

class CustomerAuthenticate extends Authenticate
{
/**
* @param array<string> $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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function panel(Panel $panel): Panel
])
->authGuard('web_customer')
->authMiddleware([
Authenticate::class,
CustomerAuthenticate::class,
]);
}

Expand Down
20 changes: 10 additions & 10 deletions web/app/Models/HostingSubscriptionBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6b2263a

Please sign in to comment.