Set custom cookie for window document?

Question:
[i’m trying to set cookie for my logged in user. after he successfully logs in i m trying to set some cookie so that i can catch it later for as users identity]2023-09-25T18:30:00Z

Product:
e-cart product

What are you trying to achieve:
export const setCookie = (cname, cvalue, exdays) =>{
const d = new Date();
d.setTime(d.getTime() + (exdays24 6060 1000));
let expires = “expires=”+ d.toUTCString();
document.cookie = cname + “=” + cvalue + “;” + expires + “;path=/”;
}

What have you already tried:
[Share resources, forum topics, articles, or tutorials you’ve already used to try and answer your question.]

Additional information:
[Include any other pertinent details or information that might be helpful for people to know when trying to answer your question.]