mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 21:54:03 +00:00
Fix PreventAccess middleware
This commit is contained in:
parent
7229691977
commit
e21f5ad76f
3 changed files with 13 additions and 4 deletions
|
|
@ -82,8 +82,9 @@ return [
|
||||||
'Stancl\Tenancy\Features\TelescopeTags',
|
'Stancl\Tenancy\Features\TelescopeTags',
|
||||||
'Stancl\Tenancy\Features\TenantRedirect',
|
'Stancl\Tenancy\Features\TenantRedirect',
|
||||||
],
|
],
|
||||||
|
'home_route' => '/app',
|
||||||
'migrate_after_creation' => false, // run migrations after creating a tenant
|
'migrate_after_creation' => false, // run migrations after creating a tenant
|
||||||
'delete_database_after_tenant_deletion' => false, // delete tenant's database after deleting the tenant
|
'delete_database_after_tenant_deletion' => false, // delete the tenant's database after deleting the tenant
|
||||||
'queue_database_creation' => false,
|
'queue_database_creation' => false,
|
||||||
'queue_database_deletion' => false,
|
'queue_database_deletion' => false,
|
||||||
'unique_id_generator' => 'Stancl\Tenancy\UUIDGenerator',
|
'unique_id_generator' => 'Stancl\Tenancy\UUIDGenerator',
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,16 @@ class PreventAccessFromTenantDomains
|
||||||
{
|
{
|
||||||
// If the domain is not in exempt domains, it's a tenant domain.
|
// If the domain is not in exempt domains, it's a tenant domain.
|
||||||
// Tenant domains can't have routes without tenancy middleware.
|
// Tenant domains can't have routes without tenancy middleware.
|
||||||
if (! in_array(request()->getHost(), config('tenancy.exempt_domains')) &&
|
$is_an_exempt_domain = in_array($request->getHost(), config('tenancy.exempt_domains'));
|
||||||
! in_array('tenancy', request()->route()->middleware())) {
|
$is_a_tenant_domain = ! $is_an_exempt_domain;
|
||||||
|
|
||||||
|
$is_a_tenant_route = in_array('tenancy', $request->route()->middleware());
|
||||||
|
|
||||||
|
if ($is_a_tenant_domain && ! $is_a_tenant_route) { // accessing web routes from tenant domains
|
||||||
|
return redirect(config('tenancy.home_route'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($is_an_exempt_domain && $is_a_tenant_route) { // accessing tenant routes on web domains
|
||||||
abort(404);
|
abort(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class Tenant implements ArrayAccess
|
||||||
*
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
protected $persisted = false;
|
public $persisted = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use new() if you don't want to swap dependencies.
|
* Use new() if you don't want to swap dependencies.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue