1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 12:44:02 +00:00

[4.x] Make ScopeSessions usable on universal routes (#1342)

* Skip ScopeSessions MW if the current context is central and the route is universal

* Add regressiont test

* Simplify code

---------

Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
lukinovec 2025-04-04 03:15:37 +02:00 committed by GitHub
parent 8cd15db1fc
commit dc90e60a2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View file

@ -19,6 +19,10 @@ class ScopeSessions
public function handle(Request $request, Closure $next): mixed
{
if (! tenancy()->initialized) {
if (tenancy()->routeIsUniversal(tenancy()->getRoute($request))) {
return $next($request);
}
throw new TenancyNotInitializedException('Tenancy needs to be initialized before the session scoping middleware is executed');
}

View file

@ -55,3 +55,15 @@ test('an exception is thrown when the middleware is executed before tenancy is i
pest()->expectException(TenancyNotInitializedException::class);
$this->withoutExceptionHandling()->get('http://acme.localhost/bar');
});
test('scope sessions mw can be used on universal routes', function() {
Route::get('/universal', function () {
return true;
})->middleware(['universal', InitializeTenancyBySubdomain::class, ScopeSessions::class]);
Tenant::create([
'id' => 'acme',
])->createDomain('acme');
pest()->withoutExceptionHandling()->get('http://localhost/universal')->assertSuccessful();
});