I am pretty new with next Js. But. I have an app where i whant to give to every client a diferent id. To do that i have a server action that gets the client id and if it dosen't exist it's going to create it. I am using cookies-next.
export async function getClientId() {
const id = await getCookie("client-id");
if (!id) {
const newId = crypto.randomUUID();
setCookie("client-id", newId, { maxAge: 60 * 60 * 24 * 365 * 20 });
return newId;
}
return id;
}
The problem is that something is wrong because the cookie dosen't get saved on the client if i add
<Button variant="link" onClick={getClientId} className="mt-4">Obține Client ID</Button>
to a file that is marked with "use server" it does not work. It generates a new cookie on every click.