Top free JavaScript User Authentication Libraries

by Janeth Kent Date: 29-01-2020 javascript authentication libraries

We are keen on security: authentication is an important issue when creating a dynamic web application

Authentication is for identifying users and provide different access rights and content depending on their id. Since new tutorials appear on the web and more people try to understand the cost-benefit equation for implementing their own solution vs. using a library or service, we have gathered a brief review of what's out there.

Let's see.

1. Passport JS

Passport is Express-compatible authentication middleware for Node.js.

Passport's sole purpose is to authenticate requests, which it does through an extensible set of plugins known as strategies. Passport does not mount routes or assume any particular database schema, which maximizes flexibility and allows application-level decisions to be made by the developer. The API is simple: you provide Passport a request to authenticate, and Passport provides hooks for controlling what occurs when authentication succeeds or fails.

Passport is not just a 15k star user-auth library, it is probably the most common way to use an external library for user authentication by JS developers. Basically, this library offers Node.js relatively flexible and modular middleware that can be integrated into any web application based on Express.

2. Permit

Before Permit, the only real choice for authentication libraries in Node.js was Passport.js. But it has a bunch of issues that complicate your codebase. Permit makes it easy to add an authentication layer to any Node.js API. It can be used with any of the popular server frameworks (eg. Express, Koa, Hapi, Fastify) and it can be used for any type of API (eg. REST, GraphQL, etc.) due to its simple, unopinionated design.

Permit lets you authenticate via the two schemes most APIs need: a single secret bearer token, or a set of username and password credentials. For example, here's how to authenticate a bearer token:

import { Bearer } from 'permit'

// A permit that checks for HTTP Bearer Auth, falling back to a query string.
const permit = new Bearer({
  query: 'access_token',

async function handler({ req, res }) {
  // Try to find the bearer token in the request.
  const token = permit.check(req)

  // No token, that means they didn't pass credentials!
  if (!token) {
    throw new Error(`Authentication required!`)

  // Authenticate the token however you'd like...
  const user = await db.users.findByToken(token)

  // No user, that means their credentials were invalid!
  if (!user) {
    throw new Error(`Authentication invalid!`)

  // They were authenticated, so continue with your business logic...

Since Permit isn't tightly coupled to a framework or data model, it gives you complete control over how you write your authentication logic—the exact same way you'd write any other request handler.

Differences between Permit and Passport:

  • Passport is not focused on authenticating APIs. Passport is focused on authenticating web apps with services like Facebook, Twitter and GitHub. APIs don't need that, so all the extra bloat means lots of complexity for no gain.

  • Passport is tightly-coupled to Express. If you use Koa, Hapi, Fastify, or some other framework you have to go to great lengths to get it to play nicely.

  • Other middleware are tightly-coupled to it. Passport stores state on the req object, so all your other middleware become tightly coupled to its implementation, making your codebase brittle.

  • It results in lots of hard to debug indirection. Because of Passport's black-box architecture, whenever you need to debug an issue it's causing you have to trace its logic across many layers of indirection and many repositories.

  • It's not very actively maintained. Passport's focus on OAuth providers means that it takes on a huge amount of scope, across a lot of repositories, many of which are not actively maintained anymore.

3. Grant

A relatively new and promising library with more than 180 supported providers and a live playground for Express, Koa and Hapi with OAuth Middleware. If you want to use it with your own private OAuth provider, you can specify the required key. Although this library already has traction (+ 1 K stars), it has relatively few resources, so try carefully.

4. Feathers

Feathers is an open source web framework for NodeJS that allows you to control your data through RESTful resources, sockets and flexible plug-ins in real time. Feathers also offers authentication and authentication management modules that allow you to add verification, forgotten reset of passwords and other features to authenticate local feathers.

The general idea is to combine multiple methods of authentication in a flexible infrastructure under one roof.

5. Firebase Authentication (for small apps)

Firebase authentication is required to provide your users with read / write privileges via security rules. We have not yet covered security rules, but we only know that security rules depend on the authentication status of a user.

Firebase ships Google, Facebook, Twitter and GitHub with its own email / password auth and OAuth2 integrations. You can also integrate your own authors with Firebase Authentication to provide users with access to data without forcing them to create an account outside your existing systems.

Firebase Auth includes a user management system. You can save some basic data against your Firebase Auth users, and you offer multiple login methods -- email/password, Google, Facebook…-- and link your users’ accounts into single Firebase Auth user accounts. Auth also provides for integrations into your pre-existing auth system so that your app can take advantage of Firebase’s security rules.

Firebase may not be the long - term solution for managing user auth on your scaling platform (or is it?). But it's a very useful way to get your applications deployed with Firebase done, quickly and easily.

Business vector created by -

by Janeth Kent Date: 29-01-2020 javascript authentication libraries hits : 18487  
Janeth Kent

Janeth Kent

Licenciada en Bellas Artes y programadora por pasión. Cuando tengo un rato retoco fotos, edito vídeos y diseño cosas. El resto del tiempo escribo en MA-NO WEB DESIGN AND DEVELOPMENT.


Related Posts

How to use the endsWith method in JavaScript

In this short tutorial, we are going to see what the endsWith method, introduced in JavaScript ES6, is and how it is used with strings in JavaScript. The endsWith method is…

What are javascript symbols and how can they help you?

Symbols are a new primitive value introduced by ES6. Their purpose is to provide us unique identifiers. In this article, we tell you how they work, in which way they…

Callbacks in JavaScript

Callback functions are the same old JavaScript functions. They have no special syntax, as they are simply functions that are passed as an argument to another function. The function that receives…

How to create PDF with JavaScript and jsPDF

Creating dynamic PDF files directly in the browser is possible thanks to the jsPDF JavaScript library. In the last part of this article we have prepared a practical tutorial where I…

How to make your own custom cursor for your website

When I started browsing different and original websites to learn from them, one of the first things that caught my attention was that some of them had their own cursors,…

Node.js and npm: introductory tutorial

In this tutorial we will see how to install and use both Node.js and the npm package manager. In addition, we will also create a small sample application. If you…

How to connect to MySQL with Node.js

Let's see how you can connect to a MySQL database using Node.js, the popular JavaScript runtime environment. Before we start, it is important to note that you must have Node.js installed…

JavaScript Programming Styles: Best Practices

When programming with JavaScript there are certain conventions that you should apply, especially when working in a team environment. In fact, it is common to have meetings to discuss standards…

Difference between arrow and normal functions in JavaScript

In this tutorial we are going to see how arrow functions differ from normal JavaScript functions. We will also see when you should use one and when you should use…

JavaScript Arrow functions: What they are and how to use them

In this article we are going to see what they are and how to use JavaScript Arrow Functions, a new feature introduced with the ES6 standard (ECMAScript 6). What are Arrow…

How to insert an element into an array with JavaScript

In this brief tutorial you will learn how to insert one or more elements into an array with JavaScript. For this we will use the splice function. The splice function will not…

What is the difference between primitives types and objects in JavaScript?

In this short tutorial we are going to look at the differences between primitive types and objects in JavaScript. To start with, we're going to look at what primitive types…