I’m new to this, i’m building a game where users need to log in and can interact with each other, or a subset of other currently logged in users.
My initial thought is that after they login add them/their websocket client id to an array of currently logged in users and have that be what I manipulate to know who is logged in or not.
Is this a normal way to go about doing this sort of thing?
Thanks!
Depends on your definition of “normal”. 😉
Typically the server you use will provide some mechanism to manage “user state” including whether or not a user has logged into your application.
For example, Node’s ‘express’ library (and ‘connect’ which express uses ‘underneath’) provides a req.session object for just this purpose so you can do things like:
Then when you want to provide protected pages to a user, first check if req.session.authorized is true and if not, redirect to a login form.
See the docs for express for more at http://expressjs.com/guide.html