Skip to content

Laravel Jetstream with Inertia tenants 302 to login #549

@svenvanhees

Description

@svenvanhees

Describe the bug

When using Jetstream with Inertia on the central and tenant domains, navigation to the user/profile pages results in a 302 redirect to /login. This only happens on the tenant routes, when using the central route, the navigation works just fine.

Steps to reproduce

New laravel project: composer create-project --prefer-dist laravel/laravel .
All steps from: https://tenancyforlaravel.com/docs/v3/quickstart
Install Jetstream as per their documentation:
composer require laravel/jetstream
php artisan jetstream:install inertia
npm install && npm run dev
php artisan migrate
php artisan vendor:publish --tag=jetstream-views
npm run dev

All steps from: https://tenancyforlaravel.com/docs/v3/features/universal-routes/

Add the universal and InitializeTenancyByDomain middleware to the config/fortify.php
'middleware' => [ 'web', 'universal', InitializeTenancyByDomain::class ],

Modify the routes/tenant.php to include the dashboard and auth:sanctum middleware.

Route::middleware([
    'web',
    'universal',
    'auth:sanctum',
    InitializeTenancyByDomain::class,
    PreventAccessFromCentralDomains::class,
])->group(function () {
    Route::get('/dashboard', function () {
        return Inertia\Inertia::render('Dashboard');
    })->name('dashboard');
});

Central Tenant
Go to http://localhost/register and create an account.
It redirects to the dashboard.
Now use the top right profile dropdown to navigate to the users profile.
Every thing works..

Foo Tenant
Go to http://foo.localhost/register and create an account. It redirects to the dashboard and by dd(Auth::check()) it seems the user is authenticated.

Now use the top right profile dropdown to navigate to the users profile.

3 navigation events happen.

GET user/profile 302 FOUND
GET login 302 FOUND
GET dashboard 200 OK

It seems the user is not authorised to visit user/profile.

Expected behavior

I expect the authentication to work on the tenant, just as it does on the central domain, but can't seem to figure out how to solve it.

Your setup

  • Laravel version: 8.17.2
  • stancl/tenancy version: 3.4.0
  • Storage driver: DB
  • Laravel/Jetstream version: 1.6.3

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions