How come in ssr, redirect works but supabase setAll doesnt?
Unanswered
Siberian Husky posted this in #help-forum
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
the redirect function ends the current stream with a new response, it doesnt try to modify the current one
setCookie function is found it can't edit the already sent headersthe redirect function ends the current stream with a new response, it doesnt try to modify the current one
@Rafael Almeida 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
Siberian HuskyOP
But I thoguth browsers can only take one response?
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
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
@Siberian Husky 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.
thats not gonna work, discord patched this quite a while ago. the links will expire if they arent refreshed within discord itself
ohhh
idk what u mean styill