How to use the @nestjs/jwt.JwtModule.registerAsync function in @nestjs/jwt

To help you get started, we’ve selected a few @nestjs/jwt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github penta-jelly / re-radio / server / src / radio / auth / auth.module.ts View on Github external
import { forwardRef, Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { ConfigModule } from 'core/config/config.module';
import { JwtConfig } from 'radio/auth/jwt.config';
import { UserModule } from 'radio/user/user.module';
import { AuthResolver } from './auth.resolver';
import { AuthService } from './auth.service';
import { JwtStrategy } from './jwt.strategy';

@Module({
  imports: [
    ConfigModule,
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useClass: JwtConfig,
    }),
    forwardRef(() => UserModule),
  ],
  providers: [AuthService, JwtStrategy, AuthResolver],
  exports: [AuthService],
})
export class AuthModule {}
github vellengs / nestx-server / packages / auth / src / auth.module.ts View on Github external
import { Module, DynamicModule } from "@nestjs/common";
import { JwtModule } from "@nestjs/jwt";
import { PassportModule } from "@nestjs/passport";
import { AuthController } from "./auth.controller";
import { AuthService } from "./auth.service";
import { JwtStrategy } from "./jwt.strategy";
import { ConfigModule, ConfigService } from "nestx-config";
import { ModuleMetadata } from "@nestjs/common/interfaces";
import { JWT_SECRET_KEY, JWT_ALGORITHM, JWT_EXPIRE_IN } from "./constants";

export const defaultMeta = {
  imports: [
    PassportModule.register({ defaultStrategy: "jwt", session: true }),
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => {
        return {
          secretOrPrivateKey: configService.get(JWT_SECRET_KEY),
          signOptions: {
            algorithm: configService.get(JWT_ALGORITHM),
            expiresIn: configService.get(JWT_EXPIRE_IN)
          }
        };
      },
      inject: [ConfigService]
    })
  ],
  controllers: [AuthController],
  providers: [AuthService, JwtStrategy]
};
github devonfw / my-thai-star / node / src / app / core / auth / auth.module.ts View on Github external
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { UserModule } from '../../user/user.module';
import { ConfigurationModule } from '../configuration/configuration.module';
import { ConfigurationService } from '../configuration/services/configuration.service';
import { AuthController } from './controllers/auth.controller';
import { AuthService } from './services/auth.service';
import { JwtStrategy } from './strategies/jwt.strategy';

@Module({
  imports: [
    UserModule,
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.registerAsync({
      imports: [ConfigurationModule],
      useFactory: (config: ConfigurationService) => config.jwtConfig,
      inject: [ConfigurationService],
    }),
  ],
  providers: [AuthService, JwtStrategy],
  exports: [AuthService, PassportModule],
  controllers: [AuthController],
})
export class AuthModule {}
github vellengs / nestx / packages / server / src / auth / auth.module.ts View on Github external
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { JwtStrategy } from './jwt.strategy';
import { ConfigModule } from './../config/config.module';
import { ConfigService } from './../config/config.service';
import { CoreModule } from './../core/core.module';
@Module({
  imports: [
    CoreModule,
    PassportModule.register({ defaultStrategy: 'jwt', session: true }),
    JwtModule.registerAsync({
      imports: [
        ConfigModule,
      ],
      useFactory: async (configService: ConfigService) => {
        return {
          secretOrPrivateKey: configService.get('JWT_SECRET_KEY'),
          signOptions: {
            algorithm: configService.get('JWT_ALGORITHM'),
            expiresIn: configService.get('JWT_EXPIRE_IN'),
          },
        };
      },
      inject: [
        ConfigService,
      ],
    }),
github devonfw / devon4node / samples / employee / src / app / core / auth / auth.module.ts View on Github external
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { AuthController } from './controllers';
import { AuthService } from './services';
import { JwtStrategy } from './strategies';
import { ConfigurationModule } from '../configuration/configuration.module';
import { ConfigurationService } from '../configuration/services';

@Module({
  imports: [
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.registerAsync({
      imports: [ConfigurationModule],
      useFactory: (config: ConfigurationService) => config.jwtConfig,
      inject: [ConfigurationService],
    }),
  ],
  providers: [AuthService, JwtStrategy],
  exports: [AuthService, PassportModule],
  controllers: [AuthController],
})
export class AuthModule {}
github devonfw / devon4node / samples / employee / src / app / core / auth / services / auth.service.spec.ts View on Github external
beforeAll(async () => {
    const module: TestingModule = await Test.createTestingModule({
      imports: [
        ConfigurationModule,
        JwtModule.registerAsync({
          imports: [ConfigurationModule],
          useFactory: (config: ConfigurationService) => config.jwtConfig,
          inject: [ConfigurationService],
        }),
      ],
      providers: [
        AuthService,
        UserService,
        {
          provide: 'UserRepository',
          useClass: UserRepositoryMock,
        },
      ],
    }).compile();

    authService = module.get(AuthService);
github SolidZORO / leaa / packages / leaa-api / src / modules / auth-token / auth-token.module.ts View on Github external
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';

import { ConfigService } from '@leaa/api/src/modules/config/config.service';
import { ConfigModule } from '@leaa/api/src/modules/config/config.module';

@Module({
  imports: [
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.registerAsync({
      inject: [ConfigService],
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        privateKey: configService.JWT_SECRET_KEY,
      }),
    }),
  ],
  exports: [PassportModule, JwtModule],
})
export class AuthTokenModule {}
github vellengs / nestx / packages / servers / nestx-auth / src / auth.module.ts View on Github external
import { Module, DynamicModule } from "@nestjs/common";
import { JwtModule } from "@nestjs/jwt";
import { PassportModule } from "@nestjs/passport";
import { AuthController } from "./auth.controller";
import { AuthService } from "./auth.service";
import { JwtStrategy } from "./jwt.strategy";
import { ConfigModule, ConfigService } from "nestx-config";
import { ModuleMetadata } from "@nestjs/common/interfaces";
import { JWT_SECRET_KEY, JWT_ALGORITHM, JWT_EXPIRE_IN } from "./constants";

export const defaultMeta = {
  imports: [
    PassportModule.register({ defaultStrategy: "jwt", session: true }),
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => {
        return {
          secretOrPrivateKey: configService.get(JWT_SECRET_KEY),
          signOptions: {
            algorithm: configService.get(JWT_ALGORITHM),
            expiresIn: configService.get(JWT_EXPIRE_IN)
          }
        };
      },
      inject: [ConfigService]
    })
  ],
  controllers: [AuthController],
  providers: [AuthService, JwtStrategy]
};
github EricKit / nest-user-auth / src / auth / auth.module.ts View on Github external
import { Module, forwardRef } from '@nestjs/common';
import { AuthService } from './auth.service';
import { PassportModule } from '@nestjs/passport';
import { JwtModule, JwtModuleOptions } from '@nestjs/jwt';
import { UsersModule } from '../users/users.module';
import { JwtStrategy } from './strategies/jwt.strategy';
import { AuthResolver } from './auth.resolvers';
import { ConfigService } from '../config/config.service';
import { ConfigModule } from '../config/config.module';

@Module({
  imports: [
    PassportModule.register({ defaultStrategy: 'jwt', session: false }),
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => {
        const options: JwtModuleOptions = {
          secret: configService.jwtSecret,
        };
        if (configService.jwtExpiresIn) {
          options.signOptions = {
            expiresIn: configService.jwtExpiresIn,
          };
        }
        return options;
      },
      inject: [ConfigService],
    }),
    forwardRef(() => UsersModule),
    ConfigModule,
github Vivify-Ideas / nestjs-boilerplate / src / modules / auth / auth.module.ts View on Github external
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { ConfigModule, ConfigService } from './../config';
import { UserModule } from './../user';
import { AuthService } from './auth.service';
import { JwtStrategy } from './jwt.strategy';
import { AuthController } from './auth.controller';

@Module({
  imports: [
    UserModule,
    ConfigModule,
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.registerAsync({
      imports: [
        ConfigModule,
      ],
      useFactory: async (configService: ConfigService) => {
        return {
          secret: configService.get('JWT_SECRET_KEY'),
          signOptions: {
            ...(
              configService.get('JWT_EXPIRATION_TIME')
                ? {
                  expiresIn: Number(configService.get('JWT_EXPIRATION_TIME')),
                }
                : {}
            ),
          },
        };

@nestjs/jwt

Nest - modern, fast, powerful node.js web framework (@jwt)

MIT
Latest version published 12 months ago

Package Health Score

83 / 100
Full package analysis

Similar packages