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

SebastianS's avatar

Why there gets no cookie set in production mode with laravel?

Hi,

I have developed an API with laravel locally. Now I would like to deploy it on a server for production mode. If I'm testing the login locally everything works fine. But nothing happens after the login trying it on the server. Anyone know why there is that problem?

My environment looks like that:

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=database
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

I think the problem is, that the cookie is not set in the browser. There is a a Response-Cookie but it does not get set. The session is also entered in the databasen the database.

Please help me, I can't resolve that problem by myself.....

0 likes
7 replies
tykus's avatar

An API usually does not maintain a session or send cookies.

SebastianS's avatar

Ok, maybe API is the wrong word. I mean the backend of my Angular application

SebastianS's avatar

I'm wondering because there is no error or something else - just nothing! It just do nothing in production mode

martinbean's avatar

@SebastianS If you’re using API routes for the “backend” of your Angular application then like @tykus says, it won’t create a session or cookies.

API routes are meant to be stateless and authenticated using a token of some sort rather than the session.

SebastianS's avatar

It's really confusing... I'm using the built-in authentication mechanism of Laravel, and everything works locally. My routes are protected by the Auth-Middleware. Why I can't use these functions of Laravel to authenticate user which are logged-in by my Angular Application? Can't get the context, sorry :-(

SebastianS's avatar

Aaaah! Is using the API Authentication instead of normal authentication the right way in this case?

martinbean's avatar
Level 80

Is using the API Authentication instead of normal authentication the right way in this case?

@SebastianS If you’re defining your routes in routes/api.php, yes. Which you should be if you’re using Angular to create a single-page application (SPA).

Your Angular code should be calling API endpoints for its data, authenticating using a token. Read the Passport documentation. It documentations how to access API routes using JavaScript.

1 like

Please or to participate in this conversation.