F
Filament14mo ago
Jappi00

Set Tenant Context in Queues and Crons

Hello together, I currently try to support multi tenancy in my application and I wounder what is the best practice to work with it in queues and crons. I have some Actions which can be triggerd from queueus, crons and the panel. The panel topic is working but in the queue and cron part I have some problems. I have tried to archive to set the tenant with the following code:
Filament::setTenant(Team::find(1));

Filament::getTenant()
Filament::setTenant(Team::find(1));

Filament::getTenant()
But it seems it needs an authenticated user. Because this is missing I receiving this error in Tinkerwell:
TYPE ERROR Filament\Events\TenantSet::__construct(): Argument #2 ($user) must be of type Illuminate\Database\Eloquent\Model|Illuminate\Contracts\Auth\Authenticatable|Filament\Models\Contracts\HasTenants, null given, called in vendor/filament/filament/src/FilamentManager.php on line 647 in phar:///Applications/Tinkerwell.app/Contents/Resources/tinkerwell/tinker.phar/vendor/psy/psysh/src/Exception/TypeErrorException.php on line 20.
TYPE ERROR Filament\Events\TenantSet::__construct(): Argument #2 ($user) must be of type Illuminate\Database\Eloquent\Model|Illuminate\Contracts\Auth\Authenticatable|Filament\Models\Contracts\HasTenants, null given, called in vendor/filament/filament/src/FilamentManager.php on line 647 in phar:///Applications/Tinkerwell.app/Contents/Resources/tinkerwell/tinker.phar/vendor/psy/psysh/src/Exception/TypeErrorException.php on line 20.
So I have tried to login the user before and it worked but I don't think taking the first user of a team is not the best practice:
Auth::loginUsingId(User::find(1)->id);
Auth::loginUsingId(User::find(1)->id);
I'am not very happy with this solution. Does anybody have a hint?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server