I have three applications: A, B, and C. The user logs in through application A. On successful login, I set a bunch of cookies. The code for the same is,
import { cookies } from "next/headers"
cookies().set(USER_ID, user_id, {
domain: process.env.DOMAIN,
path: "/",
secure: true,
httpOnly: true,
sameSite: "none",
maxAge: 60 * 60 * 24 * 7
})
After I read to application B, I tried to read this cookie using the following code,
const cookies = useCookies();
const user_id = cookies.get(USER_ID) as string;
import { useCookies } from 'next-client-cookies';
Each application is hosted on a dedicated subdomain. The problem is, that I cannot read the USER_ID from applications B and C.
In .env:
DOMAIN=’.example.com’
NOTE:
A: a.example.com
B: b.example.com
C: c.example.com
I have hosted all three under the AWS single EC2 instance.
I have tried js-cookie, and cookies-next as well. I am so confused, what’s wrong? Can someone please help?
2
If httpOnly is set to true, you cannot access the cookie from the frontend (client-side).
cookies().set(USER_ID, user_id, {
domain: process.env.DOMAIN,
path: “/”,
secure: true,
httpOnly: false,
sameSite: “none”,
maxAge: 60 * 60 * 24 * 7
})