Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using Inertia without a session #43

Merged
merged 1 commit into from
Sep 4, 2020
Merged

Allow using Inertia without a session #43

merged 1 commit into from
Sep 4, 2020

Conversation

m1guelpf
Copy link
Contributor

@m1guelpf m1guelpf commented Sep 4, 2020

This allows using Inertia for unauthenticated routes. I ran into this when moving the authentication scaffolding to Inertia, which I'll admit is outside the intended scope of the package, but still would be nice to have it working.

For anyone else running into this while this is open (or rejected), here's a hacky workaround

Add this function at the end of your app/Http/Kernel.php:

public function updateWebGroup(\Closure $closure)
{
    $this->middlewareGroups['web'] = $closure($this->middlewareGroups['web']) ?? $this->middlewareGroups['web'];

    $this->syncMiddlewareToRouter();
}

And this to the boot method of your JetstreamServiceProvider:

$this->app->make(Kernel::class)->updateWebGroup(function (array $web) {
    $web[array_search(\Laravel\Jetstream\Http\Middleware\ShareInertiaData::class, $web)] = \App\Http\Middleware\ShareInertiaData::class;

     return $web;
});

Now, copy the ShareInertiaData middleware to your local middleware folder and apply the changes of this PR.

@taylorotwell taylorotwell merged commit 78c86e6 into laravel:master Sep 4, 2020
@m1guelpf m1guelpf deleted the patch-1 branch September 4, 2020 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants