Next.js Discord

Discord Forum

How come in ssr, redirect works but supabase setAll doesnt?

Unanswered
Siberian Husky posted this in #help-forum
Open in Discord
Siberian HuskyOP
Incase you dont know, setAll is a supabase function that sets cookies in ther esponse headers usign next/headers cookies class. I want to know why you cant set cookies in a server component but you can use redirect. Im a beginner take it easy on me😩

12 Replies

when the server starts to stream a page you have a very small window to write cookies to the headers before they are flushed. so if later down in the render tree a setCookie function is found it can't edit the already sent headers

the redirect function ends the current stream with a new response, it doesnt try to modify the current one
thats a good question. i dont remember how exactly it works under the hood but when called in a server component redirect throws an error. i believe this error is sent as part of the RSC payload and a client side redirect is probably done 🤔
@Rafael Almeida thats a good question. i dont remember how exactly it works under the hood but when called in a server component `redirect` throws an error. i believe this error is sent as part of the RSC payload and a client side redirect is probably done 🤔
Siberian HuskyOP
I dont think so because the status line is 307 in my terminal
GET /dashboard 307 in 51ms (next.js: 3ms, application-code: 47ms)
GET / 200 in 26ms (next.js: 3ms, application-code: 23ms)
so its not int he payload
you would need to test this with a suspense boundary, if the redirect happens before the first response is sent then it makes sense it results in a 307 status code
i think the cookie restriction is mostly for consistency, you cant guarantee that a server component will run before the headers are sent
@Rafael Almeida i think the cookie restriction is mostly for consistency, you cant guarantee that a server component will run before the headers are sent
Siberian HuskyOP
for my storage tbh I dont feel like spending money do you think I sohuld get discord nitro and just upload all the user uplaoded stuff to discord and whenever they wanna pull it up it loads the images or videos from discord link.
sucks for discord ig lol
ohhh
idk what u mean styill