Skip to content

nestjs-authentication 1.64.9

Install from the command line:
Learn more about npm packages
$ npm install @tractr/nestjs-authentication@1.64.9
Install via package.json:
"@tractr/nestjs-authentication": "1.64.9"

About this version

nestjs-authentication

Installation

To install this librairy you have to install it first via npm, yarn or pnpm and install the required peerdependency @tractr/nestjs-database

npm i --save @tractr/nestjs-authentication @tractr/nestjs-database`

After that you need to register the module into your main application. You'll need a UserService class provider register in your app (you can user the USER_SERVICE token generate by hapify-templates-nestjs-models-common).

app.module.ts

import { Module } from '@nestjs/common';

import { AuthenticationModule } from '@tractr/nestjs-authentication';
import { DatabaseModule } from '@tractr/nestjs-database';

@Module({
  imports: [DatabaseModule.register(), AuthenticationModule.register({
    userService: 'USER_SERVICE',
  })],
  controllers: [],
  providers: [{ provide: 'USER_SERVICE', useClass: MyUserService }],
})
export class AppModule {}

You can override some options inside the register function.

Configuration

Futhermore you need to tell to nestjs to authenticate all your route. To do that you need to register the global auth guard from nestjs-authentication:

import {
  AuthenticationModule,
  JwtGlobalAuthGuard,
} from '@tractr/nestjs-authentication';

@Module({
  imports: [DatabaseModule.register(), AuthenticationModule.register()],
  controllers: [],
  providers: [
    {
      provide: APP_GUARD,
      useClass: JwtGlobalAuthGuard,
    },
  ],
})
export class AppModule {}

In the future more global auth guard will be added to the authentication package.

Cookie authentication

You need if you want to use the authentication from cookie to add the cookie parser package to your app module. You can look at the nestjs documentation. You must provide one or more secret to the cookie-parser package, `nestjs-authentication use only signedCookie in production mode.

import * as cookieParser from 'cookie-parser';
// somewhere in your initialization file
app.use(cookieParser('myScret'));

Bcrypt online generator

To be able to test you can use these bcrypt online generator to crypt your password.

Running unit tests

Run nx test nestjs-authentication to execute the unit tests via Jest.

Details


Assets

  • nestjs-authentication-1.64.9.tgz

Download activity

  • Total downloads 3
  • Last 30 days 0
  • Last week 0
  • Today 0