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

mcardosob's avatar

Cookie auth in API routes

I am building a laravel API that be consumed by my frontend (javascript).

Until now, I login my user and send a token in body response. And I consume the token with my frontend.

In my frontend app, I need to download an audio resource with the audio tag (html). To load my audio, I need to be authenticated, but I can't send auth headers with the audio tag. So the only solution is to authenticate my app with cookie token.

Can I use authenticate my user with cookies in my api routes ?

0 likes
3 replies
mcardosob's avatar

@DIEGOAURINO - Hello @diegoaurino , In the link, the cookie is attached for the web routes, so I want to attach a cookie in api routes. So, this doesn't work with api routes...

mcardosob's avatar

To recap, actaully I have a action login that send a token in body response.

But, instead of sending a token, I want to send a cookie that is accepted by passport !

Please or to participate in this conversation.