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

@nestjs-hybrid-auth/all

v1.3.0

Published

NestJS social authentication provider using passportJS

Downloads

80

Readme

NestJS Hybrid Auth All In One

Implement various social identity provider authentication in your NestJS application for e.g. Google, Facebook, Twitter and many more.

Install

npm install @nestjs-hybrid-auth/all --save

OR

yarn add @nestjs-hybrid-auth/all

How To Use?

This package is an assembling of all the individual nestjs hybrid auth provider packages and exports one single dynamic nestjs module. The module takes configuration for all social providers both synchronously and asynchronously using forRoot and forRootAsync static methods.

Example Code For app.module.ts

Simple static configuration

If you have all of your social providers credentials and configuration handy in an object, just pass them in .forRoot static method to register the module. The options object is type of HybridAuthModuleOptions.

import { HybridAuthModule } from '@nestjs-hybrid-auth/all';

@Module({
  imports: [
    HybridAuthModule.forRoot({
      google: {
        clientID: process.env.GOOGLE_CLIENT_ID,
        clientSecret: process.env.GOOGLE_CLIENT_SECRET,
        callbackURL: process.env.GOOGLE_CALLBACK_URL,
      },
      facebook: {
        clientID: process.env.FACEBOOK_CLIENT_ID,
        clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
        callbackURL: process.env.FACEBOOK_CALLBACK_URL,
      },
      // Rest of the providers
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Got Async Config For Each Provider?

If you get the configurations for each identity provider asynchronously through any config service or so, use forRootAsync static method to load them. The options would be same but value for each provider would be their AsyncOptions equivalent. Please refer to below code:

Example useFactory

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import {
  HybridAuthModule,
  FacebookAuthModuleOptions,
} from '@nestjs-hybrid-auth/all';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      cache: true,
      expandVariables: true,
    }),
    HybridAuthModule.forRootAsync({
      facebook: {
        useFactory: (
          configService: ConfigService
        ): FacebookAuthModuleOptions => ({
          clientID: configService.get('FACEBOOK_CLIENT_ID'),
          clientSecret: configService.get('FACEBOOK_CLIENT_SECRET'),
          callbackURL: configService.get('FACEBOOK_CALLBACK_URL'),
        }),
        inject: [ConfigService],
      },
      // Rest of the providers
    }),
  ],
})
export class AllAsyncFactoryModule {}

Example useClass

import { Module, Injectable } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import {
  HybridAuthModule,
  FacebookAuthModuleOptions,
  FacebookAuthModuleOptionsFactory,
} from '@nestjs-hybrid-auth/all';

// We create a config provider class for useClass
@Injectable()
export class FacebookAuthConfig implements FacebookAuthModuleOptionsFactory {
  constructor(private configService: ConfigService) {}

  createModuleOptions(): FacebookAuthModuleOptions {
    return {
      clientID: this.configService.get('FACEBOOK_CLIENT_ID'),
      clientSecret: this.configService.get('FACEBOOK_CLIENT_SECRET'),
      callbackURL: this.configService.get('FACEBOOK_CALLBACK_URL'),
    };
  }
}

// Actual app module
@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      cache: true,
      expandVariables: true,
    }),
    HybridAuthModule.forRootAsync({
      facebook: {
        useClass: FacebookAuthConfig,
      },
      // Rest of the providers
    }),
  ],
})
export class AllAsyncClassModule {}

Exports For Controller File

@nestjs-hybrid-auth/all just re-exports all the authentication route guards and result interfaces from all the individual identity providers. For more information, you can check the documentation for any provider for e.g.@nestjs-hybrid-auth/google.

Have Issues?

If you still have trouble setting up the workflow properly, please file an issue at Issues page.

Maintainers

Manish Jangir