@bitloops/bl-boilerplate-infra-nest-auth-passport
Version:
TypeScript postgres package for Bitloops Language generated projects
52 lines (51 loc) • 2.01 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var JwtAuthModule_1;
import { Module } from '@nestjs/common';
import { JwtModule, } from '@nestjs/jwt';
import { JwtStrategy } from './jwt.strategy';
import { JWT_SECRET } from './constants';
let JwtAuthModule = JwtAuthModule_1 = class JwtAuthModule {
static register(options) {
return {
module: JwtAuthModule_1,
imports: [JwtModule.register(options)],
providers: [
JwtStrategy,
{
provide: JWT_SECRET,
useValue: options.secret,
},
],
exports: [JwtModule],
};
}
static registerAsync(options) {
return {
module: JwtAuthModule_1,
imports: [JwtModule.registerAsync(options)],
providers: [
JwtStrategy,
{
provide: JWT_SECRET,
useFactory: async (...args) => {
if (!options.useFactory) {
throw new Error('No useFactory function provided');
}
return (await options.useFactory(...args)).secret;
},
inject: options.inject,
},
],
exports: [JwtModule],
};
}
};
JwtAuthModule = JwtAuthModule_1 = __decorate([
Module({})
], JwtAuthModule);
export { JwtAuthModule };