1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 09:54:05 +00:00

Add AuthTenancyBootstrapper.

It'll remove the 'auth.password' singleton from the container. This will ensure a new instance is created when another tenant needs it in the same app lifecycle.

Fixes #1052
This commit is contained in:
Bram Wubs 2023-02-08 10:26:08 +01:00
parent 7d59ff180f
commit 8bc37a3f4e
3 changed files with 48 additions and 5 deletions

View file

@ -32,6 +32,7 @@ return [
Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper::class, Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper::class,
Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper::class, Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper::class,
Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper::class, Stancl\Tenancy\Bootstrappers\QueueTenancyBootstrapper::class,
Stancl\Tenancy\Bootstrappers\AuthTenancyBootstrapper::class,
// Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper::class, // Note: phpredis is needed // Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper::class, // Note: phpredis is needed
], ],

View file

@ -0,0 +1,21 @@
<?php
namespace Stancl\Tenancy\Bootstrappers;
use Illuminate\Support\Facades\App;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant;
class AuthTenancyBootstrapper implements TenancyBootstrapper
{
public function bootstrap(Tenant $tenant)
{
// empty
}
public function revert()
{
App::forgetInstance('auth.password');
}
}

View file

@ -10,6 +10,7 @@ use ReflectionProperty;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Stancl\JobPipeline\JobPipeline; use Stancl\JobPipeline\JobPipeline;
use Stancl\Tenancy\Bootstrappers\AuthTenancyBootstrapper;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
@ -201,6 +202,26 @@ class BootstrapperTest extends TestCase
$this->assertEquals($expected_storage_path, $new_storage_path); $this->assertEquals($expected_storage_path, $new_storage_path);
} }
/**
* @test
*/
public function it_resets_the_auth_password_singleton_after_tenant_switch(): void {
config(['tenancy.bootstrappers' => [
AuthTenancyBootstrapper::class,
]]);
$tenant1 = Tenant::create();
$tenant2 = Tenant::create();
tenancy()->initialize($tenant1);
$manager = app('auth.password');
tenancy()->end();
tenancy()->initialize($tenant2);
$manager2 = app('auth.password');
$this->assertFalse($manager === $manager2);
}
protected function getDiskPrefix(string $disk): string protected function getDiskPrefix(string $disk): string
{ {
/** @var FilesystemAdapter $disk */ /** @var FilesystemAdapter $disk */