Create random id for a non logged in user


#1

Hello,

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.

Thanks.


#2

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

let clientId = someLocaleStorage.get('lastMeteorClientId') || Random.id()
someLocaleStorage.set('lastMeteorClientId',clientId);

//do stuff

#3

Thank you streemo, I will try it out.


#4

Hi streemo,

it works thank you very much


#6

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.


#7

Well a quick google search shows this: http://stackoverflow.com/questions/1631959/how-to-capture-the-browser-window-close-event


#8

The following thread might help: