Create random id for a non logged in user



I am creating an app where non logged in users can draw wood plates. First I tried the artwells/meteor-accounts-guest package and it works fine. But then I remembered that the server broke a connection after a given time and meteor made a reconnect. After the reconnect the same user got a new userid and all user inputs and data lost on the screen.
Now I want to try the following way without the artwells package. If the user go on my page without login, he get a random id which will be stored in a persistent session. All data which is created by the current user, will be stored according to the id from the persistent session. If the server break the connection, the created id will stay inside the persistent session and the user continue without loosing the data.
My question is, is this a good way? If yes, do anyone know how can I create a random id. If not, please tell me a better way to solve my issue.

P.S: please forgive me for the bad english.



Using local storage is a pretty standard way of doing this.

let clientId = someLocaleStorage.get('lastMeteorClientId') ||

//do stuff


Thank you streemo, I will try it out.


Hi streemo,

it works thank you very much


I have an additional question, is there a way to check is the browser window closed, not the tab and not reload a window. I want to clean db only if the user close the browser.


Well a quick google search shows this:


The following thread might help: