Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

monty75's avatar

Session expired (error 419) during login and registration after deployment

Hi. After deploying a Laravel/VueJS (5.7) application on a production server, the login and registration attempts fail immediately with a "session has expired" error (419). I've used Laravel Passport for authentication. Everything is working correctly on the development server. Any idea on the origin of the problem?

0 likes
16 replies
satiseven777's avatar

see session.php in conf file! if you using https you should disable http_only!if you dont have table for storing session change the driver to file! see storage/framework/sessions after try for login or register and control that new file has been created or not!

realrandyallen's avatar

Is your APP_KEY set in your .env file? If not run:

php artisan key:generate and try again

1 like
monty75's avatar

Thanks for your reply. http_only was already disabled. Sessions are stored as files and they exist under storage/framework/sessions. After removing them and trying to login or to register a new user, I still have the same error.

monty75's avatar

@REALRANDYALLEN - Thanks for your reply Randy. New keys were generated after deployment and they're present in the .env file. I'm using the file driver and the session files are well generated after a login or a registration. The 419 error is displayed immediately after a login or a registration.

realrandyallen's avatar

@MONTY75 - Hrm, this is usually a CSRF token issue but since you've deployed it to production I'm assuming it worked locally so that shouldn't be an issue...but you could always temporarily disable CSRF protection and test just to eliminate it as an issue

in app/http/Kernel.php just comment out

\App\Http\Middleware\VerifyCsrfToken::class,
1 like
realrandyallen's avatar

@MONTY75 - I'm glad it fixed it; however, you really need to uncomment that line and leave it on or you've introduced a security hole in your system. I only suggested to comment it out temporally in order to prove it was the issue...but:

Are you properly adding the CSRF token to all your forms?

<form method="POST" action="/profile">
    {{ csrf_field() }}
    ...
</form>

https://laravel.com/docs/5.5/csrf#csrf-introduction

1 like
monty75's avatar

@REALRANDYALLEN - @csrf are present in all my forms. I've installed barryvdh/laravel-cors to send CORS headers but it didn't solve the problem. Maybe the problem is coming from axios or vue-axios, not Laravel.

realrandyallen's avatar

@MONTY75 - Are you sending your token in the payload as well when you post via axios in your Vue components?

ahmedmuneer's avatar

I have took my friend .env file then pasted and were struggling for two days for this issue i have generated a new KEY but still showing the same problem

Melayyoub's avatar

If you guys met this expired issue it's not about the key only, it's about the env file, check your cache, key, and host

some cases ... CACHE_DRIVER= SESSION_DRIVER=file QUEUE_DRIVER=sync ...

should be =file, not null

hope this help

pedrojaphed's avatar

For me, deleting session_domain from .env solved the issue

Eleetgeek's avatar

I encountered the same problem and I realised that it is caused by having an active session in the Local instance while trying to login to the Live instance. Try logging out the localhost instance.

CutePotato's avatar

Remember then work in local without SSL you want to have unset SESSION_SECURE_COOKIE in .env

2 likes

Please or to participate in this conversation.