Problem getting cookie in API route #54840
Replies: 4 comments 14 replies
-
|
Could you provide a repro? The GET handler should be able to get the |
Beta Was this translation helpful? Give feedback.
-
|
I think the cookies().get('token') is getting from the client (browser cookie jaw). |
Beta Was this translation helpful? Give feedback.
-
|
cookies().getAll() does not work in Route Handler, IF AND ONLY you make request from the SERVER COMPONENT. However, if you want to use SERVER COMPONENT then no need to make request to route handler, you can get directly cookies() itself, make use of this cookies to do whatever authentication you need to do. I also have the same problem, this is how i am able to solve my problem |
Beta Was this translation helpful? Give feedback.
-
|
I found one hacky solution which is works for me Server action now route handler I can get from header |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'm implementing an authentication flow where I can save a cookie, see it in storage and manipulate it through a server component.
However, I'm having trouble getting this cookie in a route API, all my attempts return an undefined or null.
The code to set cookie
(Using cookies from next/headers)
Showing stored cookie
The result in API Route
Working in server component
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions