Chapter 3. Nest.js authentication
Nest.js, using version 5 the @nestjs/passport
package, allows you to implement the authentication strategy that you need. Of course you can also do this manually using passport
.
In this chapter you will see how to use passport by integrating it into your Nest.js project. We also cover what a strategy is, and how to configure the strategy to use with passport.
We will also manage restriction access using an authentication middleware, and see how guards can check data before the user accesses the handlers. In addition, we’ll show how to use the passport package provided by Nest.js in order to cover both possibilities.
As an example, we will use the following repository files:
/src/authentication
/src/user
/shared/middlewares
/shared/guards