When making some kind of full stack node.js application I will want to have some kind of way to make it so I can have at least something that can work as user accounts. Maybe it would be best to have some kind of system that authenticates by way of doing something with oAuth, but maybe not, maybe I just want some kind of basic user id system, I see some projects that do that.
The reason why I just got into doing this is because I have just started making full stack apps that I can host on heroku.
Well I have found a great node.js solution that can be used to generate user ids called shortid.
For a basic example of using shortId I just put together something that just responds to a request with a new id each time.
So My actual user account system is a little more advanced.
- A client system is delivered to the client.
- The client system makes a post request to the back end with a user id if stored in local storage
- If the client system does not have a user id is sends a post request with a user id of undefined
- If the back end gets a user id it checks if it has a *.json file that corresponds to that id.
- If the back end has a *.json file for that id it will update, and respond with that record.
- If it does not have a record that corresponds to the given id, or it is given undefined it will generated and return a new record, and id.
So for now I have this all in one index.js file.
I am also making use of a simple client system in a public folder that just consists of a sinle index.html file that makes a post request to the back end.
So far the system works as expected, but I have not at all put it threw a meat grinder. One thing that bothers me with it so far is that I will end up with thousands of *.json files in the users folder, but when I think about it a lot of data will have to be stored some how. In any case I am not attached to the way that the user accounts are stored.
I might work on this more, because I would like a system like this for when making some kind of full stack application, but it might just end up being yet another one of my little prototypes.