I am making a NextJS app. I am using cookies to save access tokens returned from REST API.
In login.js, cookies are being created successfully:
document.cookie = `token=${res.data.result.accessToken}; path=/;`;
but when I access it in header.js :
if (document.cookie.split(';').some((item) => item.trim().startsWith('token='))) {
SetAuth("true");
}
it says;
ReferenceError: document is not defined
Any reason, or any other way to save tokens and access them?