npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@trxn/nestjs-authentication

v3.0.0

Published

The nestjs-authentication module is that will handle your authentication. It will by give you access to some standard guard to use jwt and login based strategy authentication. Under the hood this module use jwt and passport to authenticate the connections

Downloads

106

Readme

Authentication Module

The nestjs-authentication module is that will handle your authentication. It will by give you access to some standard guard to use jwt and login based strategy authentication. Under the hood this module use jwt and passport to authenticate the connections.

Installation

You can install the nestjs-authentication module using npm:

npm install --save @trxn/nestjs-authentication

Getting Started

In your workspace create you own AuthenticationModule that will configure the AuthenticationModule.

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

import { AuthenticationModule } from '@trxn/nestjs-authentication';
import { UserModule } from './user.module';

@Module({
  imports: [AuthenticationModule.register({
    imports: [UserModule]
  })],
})
export class AppModule {}

The UserModule here is the UserModule provided by @trxn/nestjs-user and that expose a UserService. You can use your own UserService class by providing it directly in the options:

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

import { AuthenticationModule } from '@trxn/nestjs-authentication';
import { UserModule } from './user.module';

@Module({
  imports: [AuthenticationModule.register({
    UserService: MyUserServiceClass
  })],
})
export class AppModule {}

The UserService property respect the nestjs Provider type.

Configuration

After the first configuration your routes are not yet protected. Authentication Module give access to you to some guard class that you can use across your project. One of the best method to authenticate your application is to force the authentication to all the routes of your application and whitelist only the route that you need to be public. To do so AuthenticationModule give you access a guard and a decorator @Public to mark the route as public.

Here an example to authenticate all your routes:

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

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

CustomUserSelect

The AuthenticationModule is responsible to hydrate you user when a request hit your api. Some time you don't want only the user but you want to join some data attached to it. This module let you configured a object that will be used in junction with the `UserService`` provided to select the information to use to fetch the user.

@Module({
  imports: [
    AuthenticationModule.register(
      //... the UserService configuration

      customSelect: {
        id: true,
        roles: true,
        profile: {
          name: true,
          address: true,
          // ...
        }
      }
    ),
  ],
  controllers: [],
  providers: [
    {
      provide: APP_GUARD,
      useClass: JwtGlobalAuthGuard,
    },
  ],
})
export cla

## 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](https://docs.nestjs.com/techniques/cookies#cookies).
**You must provide one or more secret to the cookie-parser package**,
`nestjs-authentication` use only signedCookie in production mode.

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

Encryption

By default AuthenticationModule use Bcrypt to parse and read the password. If you need to use something else you can provide to the AuthenticationModule your own EncryptionService that need to implement a compare and a hash method.

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

You can look at the BcryptModule to found some example.

Bcrypt online generator

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