How can I get httpOnly cookies in server components in the app directory?
Unanswered
Black carp posted this in #help-forum
Black carpOP
I have httpOnly cookies that I need to access in server components but these cookies aren't sent with the RSC request, how can I get nextjs to include credentials to its RSC requests?
10 Replies
Tonkinese
HI, did you manage to solve this?
@Tonkinese HI, did you manage to solve this?
Black carpOP
Unfortunately I didn't, in my case converting the server component to a client component and calling my API directly from the client was a sufficient solution...
@Black carp Unfortunately I didn't, in my case converting the server component to a client component and calling my API directly from the client was a sufficient solution...
fetch("", {
headers: Object.fromEntries(headers())
})this should do it
@Ray ts
fetch("", {
headers: Object.fromEntries(headers())
})
this should do it
Black carpOP
I think I tried it once and it didn't work, I just tried it again and the RSC just won't make a request to my
loclahost:3001 server at all... might need to fix that issue first@Ray cached?
Black carpOP
No, it's just saying "failed to fetch"
I need to update to 14.1 to get better logs and go in depth, might have time tomorrow fo this, this issue is one that I opened a long time ago so I need to refocus on it
@Black carp Unfortunately I didn't, in my case converting the server component to a client component and calling my API directly from the client was a sufficient solution...
Tonkinese
okay, this is what i ended up doing as well. its a shame as i cant utilise the server side rendering onload
@Tonkinese okay, this is what i ended up doing as well. its a shame as i cant utilise the server side rendering onload
have you tried this?
fetch("", {
headers: Object.fromEntries(headers())
})Tonkinese
No, i will give this a go at some point and let you know. thanks