mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 09:34:04 +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:
parent
8cd15db1fc
commit
dc90e60a2f
2 changed files with 16 additions and 0 deletions
|
|
@ -19,6 +19,10 @@ class ScopeSessions
|
||||||
public function handle(Request $request, Closure $next): mixed
|
public function handle(Request $request, Closure $next): mixed
|
||||||
{
|
{
|
||||||
if (! tenancy()->initialized) {
|
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');
|
throw new TenancyNotInitializedException('Tenancy needs to be initialized before the session scoping middleware is executed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,3 +55,15 @@ test('an exception is thrown when the middleware is executed before tenancy is i
|
||||||
pest()->expectException(TenancyNotInitializedException::class);
|
pest()->expectException(TenancyNotInitializedException::class);
|
||||||
$this->withoutExceptionHandling()->get('http://acme.localhost/bar');
|
$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();
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue