Server-side cookie
Cookie options
How to create a cookie?
const crypto = require('crypto');
const cookieName = 'truid'; // this is just an example name, you can change it to what you want
const userId = `${crypto.randomUUID()}-${Date.now()}`;
const expirationDate = new Date(2037, 11, 20).toUTCString();
const domainCookie = '.mysite.com'; // change mysite.com to your domain
const cookieString = `${cookieName}=${userId}; SameSite=LAX; Expires=${expirationDate}; Domain=${domainCookie}; HttpOnly; Secure`;
// add cookieString to your headers under key set-cookie
response.writeHead(200, {
"Set-Cookie": cookieString
});
Last updated
Was this helpful?

