My struggle lies in setting cookies with the cookies
function within Next.js. While everything works smoothly on localhost, the production environment seems to render empty cookie values. The peculiar thing is that these cookies are being set by the Next.js server itself. This is how I am going about it:
const cookieStore = cookies();
cookieStore.set({
name: "accessToken",
value: res.data?.google?.access,
httpOnly: true,
secure: true,
path: "/",
maxAge: 3600,
expires: new Date(Date.now() + 3600),
sameSite: "strict",
});
cookieStore.set({
name: "refreshToken",
value: res.data?.google?.refresh,
httpOnly: true,
secure: true,
path: "/",
maxAge: 7 * 24 * 60 * 60,
expires: new Date(Date.now() + 7 * 24 * 60 * 60),
sameSite: "strict",
});
Despite attempting various solutions such as those found in Client not saving cookies in production, Cookies are not being set in production, and Cookies Not Being Set in Production in Next.js App, none have proven effective in resolving my issue.
As a side note, my setup involves using Next.js V15 rc.