Implementing basic authentication
Most applications need a way to authenticate users. In this recipe, we will create a simple form to create and authenticate users. We will keep our authenticated users in the session so that we can maintain our authenticated state even when the page is refreshed. In order to get our users, we will pass a random token to the socket, once it authenticates, that it can use to retrieve the authenticated profile.
Getting ready
For this recipe, we will use MongoDB to persist our users. We will also use the the md5 npm
module to hash our passwords before we save them to the database.
How to do it…
To implement basic authentication, follow these steps:
- First, we will need to create our server. The server will require several ...
Get Socket.IO Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.