cookie Server component
Unanswered
Alaskan Klee Kai posted this in #help-forum
Alaskan Klee KaiOP
Authentication feature of DRF.
When using an api that requires authentication, I had to include authentication information in credentials:include.
In the server component, it seems that even if I include authentication information in credentials:include, the cookie is not sent: even if "include" is given as a request setting, the cookie is not sent.
What should I do in this case?
Please let me know. Best regards.
When using an api that requires authentication, I had to include authentication information in credentials:include.
In the server component, it seems that even if I include authentication information in credentials:include, the cookie is not sent: even if "include" is given as a request setting, the cookie is not sent.
What should I do in this case?
Please let me know. Best regards.
5 Replies
Japanese anchovy
When a fetch request is on the server, credentials include will not work. you need to attach the values manually. In my case, i attach the Authorization header with the Bearer token. now on the client you can use that Credentials: inlclude and all your cookies will get sent along with the request.
const data = await fetch('myauthedUrl', {
headers: {
'Authorization': 'Bearer [whatever]'
}
}).then(res => res.json());of course in your case you may want to just include the cookies from the current request
Keep in mind that any access of headers in a page will opt that route into SSR
That may or may not be an issue for you depending on your needs.
Alaskan Klee KaiOP
@Japanese anchovy thank you for reply
I will try it
I will try it