Passport
Passport is a well known library that is popular and flexible to use. In fact, passport is flexible middleware that can be fully customized. Passport allows different ways to authenticate a user like the following:
local strategy
that allows you to authenticate a user just with it’s own dataemail
andpassword
in most cases.jwt strategy
that allows you to authenticate a user by providing a token and verifying this token usingjsonwebtoken
. This strategy is used a lot.
Some strategies use the social network or Google in order to authenticate the user with a profile such as googleOAuth
, Facebook
, or even Twitter
.
In order to use passport you have to install the following package: npm i passport
. Before you see how to implement the authentication, you must implement the userService
and the userModel
.