fix: ignore tenant cookies on unauthenticated Nova pages
This commit is contained in:
3 files changed
+25
No files matched your search
@@ -2,6 +2,12 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Ignore a persisted tenant cookie while Nova is serving an unauthenticated page, such as the login screen.
|
||||
|
||||
## [1.0.0] - 2026-09-09
|
||||
|
||||
### Added
|
||||
|
||||
@@ -3,12 +3,22 @@
|
||||
namespace MeghdadFadaee\NovaTenancy\Providers;
|
||||
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use LogicException;
|
||||
use MeghdadFadaee\NovaTenancy\Contracts\ProvidesNovaTenants;
|
||||
|
||||
class UserTenantProvider extends EloquentTenantProvider
|
||||
{
|
||||
public function find(Request $request, int|string $key): ?Model
|
||||
{
|
||||
if ($request->user() === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return parent::find($request, $key);
|
||||
}
|
||||
|
||||
public function query(Request $request): Builder
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
@@ -30,6 +30,15 @@ it('resolves only an accessible tenant from the cookie', function (): void {
|
||||
expect((new CurrentTenant(new UserTenantProvider, $request))->model())->toBeNull();
|
||||
});
|
||||
|
||||
it('ignores a persisted tenant cookie for unauthenticated requests', function (): void {
|
||||
$request = Request::create('/nova/login');
|
||||
$request->cookies->set('nova_tenant', '1');
|
||||
|
||||
$context = new CurrentTenant(new UserTenantProvider, $request);
|
||||
|
||||
expect($context->model())->toBeNull();
|
||||
});
|
||||
|
||||
it('provides scoped string bindings and strict accessors', function (): void {
|
||||
expect(app('CurrentTenantId'))->toBeNull()
|
||||
->and(app('CurrentTenantModel'))->toBeNull()
|
||||
|
||||
Reference in new issue
Block a user