'Get unique user identificator, which doesn't change even upon page refresh

Is there any trick to get a unique user identifier, which doesn't change, when the user refreshes the browser? I've tried socket.io and sessionID from express, but those change when the user refreshes the browser.

Why? I'm trying to make a game without the need to log in. The User class will create a lobby with friends and then start the game, which will be locked for any other users, but I want to make the feature, that if the user who has already started/joined any game will refresh the browser, he will be reconnected to his game.

I'd already set up the database which is ready for the unique user identifier, so the lobby/game will know who will be authorized to join and who will be not.

Code of how my sessions are set up:

const sessions = require('express-session');

...

app.use(sessions({
    secret: "thisismysecretkey",
    saveUninitialized: true,
    resave: false
}));

...

app.post("/lobby/:id", (req, res) => {
  console.log(req.sessionID)
});

With this set up, the sessionID is constantly changing when the requests are from the same user.

P.S. Yes, the secret code is unsafe, I will change it after I will make it work.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source