cookies not coming in fetch call from a server component
Unanswered
Sedge Wren posted this in #help-forum
Sedge WrenOP
I'm trying to setup supabase auth in my app and created a function to get the user after creating supabase client in a 'use server' headed file. I've included the api routes in the middleware. Now I want to use this function in my route handlers. If I call the api from a client component using fetch, the user is coming. However if I call the fetch in server component, the user is not coming in the route handlers. I can see the user in server component. I've included credentials:"include" in the fetch call too, still the user is not coming. My middleware file matches the api routes too. Any help is greatly appreciated! Thanks for your time.
2 Replies
@Sedge Wren I'm trying to setup supabase auth in my app and created a function to get the user after creating supabase client in a 'use server' headed file. I've included the api routes in the middleware. Now I want to use this function in my route handlers. If I call the api from a client component using fetch, the user is coming. However if I call the fetch in server component, the user is not coming in the route handlers. I can see the user in server component. I've included credentials:"include" in the fetch call too, still the user is not coming. My middleware file matches the api routes too. Any help is greatly appreciated! Thanks for your time.
the cookie does get sent, but it is only setting the cookie to the server, not to the browser. setting the cookie to the server doesn't make sense, so nothing happens.
server component cannot set cookies. you have to use middleware, server actions or a route handler called from the client.
server component cannot set cookies. you have to use middleware, server actions or a route handler called from the client.
Sedge WrenOP