Auth System - Cookie problem

Hey, I have another question. I'm currently trying to convert my AuthSystem from Next 14 to Next15. the cookie set works
(await cookies()).set('viewToken', data, {
httpOnly: true,
maxAge: 24 * 60 * 60,
sameSite: “strict”
});
(await cookies()).set('viewToken', data, {
httpOnly: true,
maxAge: 24 * 60 * 60,
sameSite: “strict”
});
but the cookie get does not work with uploadthing in the middleware or in the trpc context
8 Replies
julius
julius2mo ago
where are you setting the cookie
DevPanda
DevPandaOP2mo ago
on my api route, or give it a better way with trpc?
julius
julius2mo ago
https://github.com/pingdotgg/uploadthing/blob/main/playground/lib/actions.ts#L15-L32 we call this from server action but this works you should be able to set cookies from route handlers too
DevPanda
DevPandaOP2mo ago
okay ty. i try it
julius
julius2mo ago
as long as you're not streamign that orute handler
DevPanda
DevPandaOP2mo ago
how do you mean?
julius
julius2mo ago
http doesn't support setting headers after response has been sent https://nextjs.org/docs/app/api-reference/functions/cookies#good-to-know
DevPanda
DevPandaOP2mo ago
Okay that means I can´t do login route with trpc. because I can't set a cookie because it's not a serveraction or route handler. As I understand it, I can only do it via API route because this is executed directly on the server side and not with trpc. sorry i always need a little longer to understand things ? fixed sameSite "lax" was the solution @julius ty

Did you find this page helpful?