I am currently learning the MERN stack, having previously worked mostly in Django. However, I find myself recoding the same things over and over again manually and not being entirely satisfied with the end product, such as programming a user database, roles, and permissions. In Django, this is all done automatically, which I loved.

Is there a library I can simply install with npm that acts more or less the same way? Should this be handled on the backend in NodeJS or Express, or in the frontend with React? What are the best practices for this?

The library should be able to do the following: create and modify users assign roles to users assign permissions to roles


Well, I had the same problem. I started learning React and Node.js after exploring in-depth Django, with all its automation and out of the box provided features. Also recently, I was wondering what it could be the best option for user authentication, and I came up with Single Sign-On (SSO), OAuth & OpenID Connect. I found that they are used by most big companies and organizations. Unfortunately, things are not as easy as with Django, but there are much more modern, secure, scalable, and the following library is used by most of the developers nowadays. So, I would recommend you to use a library called Passport.js. It is really nice, easy to learn, friendly for the developer and of course it is the primarily library for user authentication in Node.js.

Its philosophy is to provide various strategies for developers and applications. A strategy is an authentication mechanism. For example, local authentication (with sessions & cookies) or something like Facebook / Google login. Last but not least, I prompt you to watch multiple tutorials about Passport.js on YouTube and make comfortable yourself with the OAuth & OpenID Connect protocols, as well as with JWT and how authentication can be implemented without sessions.

*You should always handle authentication in the backend, for security purposes.

I hope that helps! Please let me know if you need more help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.