Login / logout mess when Turbolinks enabled

Whenever I have Turbolinks enabled, logout and re-login does not work properly.

First the logout method returns a redirect which did not seem to work with Turbolinks (URL was still /logout instead of /login). I can get around it using this middleware https://github.com/code-orange/turbolinks-location.

Re-login, however, does not work. Either the user is logged out immediately after re-login or I get a 419 response from livewire (login is a Livewire component).

As soon as I comment Turbolinks.start() in app.js everything works fine.

I’m wondering if somebody has made the same experience and found a reason / solution.

$(document).on("submit", "form[method=post]", function(e) {

    Turbolinks.visit(this.action+(this.action.indexOf('?') == -1 ? '?' : '&')+$(this).serialize());

    return false;

}

@hortigado thanks for the reply, but it makes no difference. Getting a 419 response from Livewire on re-login.

What should that do? Serialize post parameters to query parameters? What is this.action?

This prevents the page from reloading in forms so it keeps running turbolinks. So if you log in with a form, the page will not reload when you log in.
I’m going to use that middleware to see if it gives me your problem.

Is your APP_KEY set in your .env file?

also in kernel.php put VerifyCsrfToken,the middleware is not the problem.
protected $middlewareGroups = [
‘web’ => [
\App\Http\Middleware\VerifyCsrfToken::class,
]

Ok, thanks for the explanation. But really makes no difference in my setup.

APP_KEY is set and the CSRF middleware is in the web group.

If you use the csrf token in the form ?. Also try
php artisan key: generate

php artisan config:cache

Tried all that - no success.

But since it happens only for login / logout, don’t you think it has something to do with the session …