Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {}
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]
};
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 {}
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,
],
}),
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 {}
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);
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 {}
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]
};
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,
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')),
}
: {}
),
},
};