Next.js Discord

Discord Forum

Get auth cookie and forward it.

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
I have this case where on the server side I need to get the users auth cookie and pass it on in a fetch call.

However I am not sure how to get the cookie as they have weird names.
What is the best way to get the cookie to pass it on server side?

10 Replies

English Angora
Firstly you need to create cookie on server and then send to client
Sun bearOP
yes but how do I get the right cookie?

I need to pass the cookie to a fetch api endpoint so i have access to the currently logged in user
English Angora
you are fetching data on client side or server side ?
Sun bearOP
server side.
I do a fetch request to a nextjs api endpoint from server side and i notice the fetch does not pass along the cookies so it doesnt know the context
English Angora
you are using route handlers ?
Sun bearOP
I am on a normal page
that does a request to a api route
English Angora
you are on a server component or client component ?
Sun bearOP
server
ah i think I have it:
const cookieStore = cookies();
cookieStore.toString()