I am trying to set cookies that have to be persistent even if the user closes the browser.
document.cookie = name=${generateString()}; 'expires=Sun, 1 Jan 2023 00:00:00 UTC; path=/';
But when I close the window, and I open it again there is no cookie saved.
My goal is to save somehow the current user without him/her being logged and create a temporary user.
You should consider using localStorage. For example:
// setting an item with name "expires"
localStorage.setItem('expires', 'Sun, 1 Jan 2023 00:00:00 UTC');
// retrieving the item
const expires = localStorage.getItem('expires');