This package provides JSON Web Token (JWT) utilities and helps create tokens for use in authentication and authorization of web requests to your NestJS application. It contains a JwtModule that exposes a single JwtService provider to sign, verify and decode JWT tokens, either synchronously or asynchronously. The JwtService is configured with options (via JwtModuleOptions) that correspond to config of the NodeJS jsonwebtoken package used underneath.
Provides JWT utilities module for NestJS based on the jsonwebtoken package.
From the documentation:
The
@nestjs/jwt
package is a utility package that helps with JWT manipulation. Thepassport-jwt
package is the Passport package that implements the JWT strategy and@types/passport-jwt
provides the TypeScript type definitions.
From the project README.md:
Installation
$ npm i --save @nestjs/jwt
Usage
Import
JwtModule
:@Module({ imports: [JwtModule.register({ secret: 'hard!to-guess_secret' })], providers: [...], }) export class AuthModule {}
Inject
JwtService
:@Injectable() export class AuthService { constructor(private readonly jwtService: JwtService) {} }