UNPKG

nest-phylax

Version:

Security library for NestJS

74 lines 3.5 kB
"use strict"; 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; Object.defineProperty(exports, "__esModule", { value: true }); exports.JwtAuthModule = void 0; const common_1 = require("@nestjs/common"); const controllers_1 = require("./controllers"); const jwt_auth_service_1 = require("./services/jwt.auth.service"); const common_2 = require("../common"); let JwtAuthModule = JwtAuthModule_1 = class JwtAuthModule { static forRoot(options) { if (!options.accessTokenConfig) { throw new Error('accessTokenConfig is required'); } let controllers = []; if (!options.disableControllers) { if (options.refreshTokenConfig) { controllers = [controllers_1.RefreshTokenController, controllers_1.PasswordLoginController]; } else { controllers = [controllers_1.PasswordLoginController]; } } return { module: JwtAuthModule_1, providers: [ { provide: common_2.JWT_AUTH_MODULE_OPTIONS_TOKEN, useValue: { disableControllers: options === null || options === void 0 ? void 0 : options.disableControllers, accessTokenConfig: options.accessTokenConfig, refreshTokenConfig: options === null || options === void 0 ? void 0 : options.refreshTokenConfig, }, }, { provide: common_2.JWT_GENERATION_OPTIONS_TOKEN, useValue: { accessTokenConfig: options.accessTokenConfig, refreshTokenConfig: options === null || options === void 0 ? void 0 : options.refreshTokenConfig, }, }, Object.assign({ provide: common_2.USER_REPOSITORY_TOKEN }, options.userRepositoryProvider), Object.assign({ provide: common_2.PASSWORD_ENCODER_TOKEN }, options.passwordEncoderProvider), jwt_auth_service_1.JwtAuthService, ], controllers, exports: [ jwt_auth_service_1.JwtAuthService, { provide: common_2.JWT_AUTH_MODULE_OPTIONS_TOKEN, useValue: options, }, { provide: common_2.PASSWORD_ENCODER_TOKEN, useValue: options.passwordEncoderProvider, }, { provide: common_2.USER_REPOSITORY_TOKEN, useValue: options.userRepositoryProvider, }, ], }; } }; JwtAuthModule = JwtAuthModule_1 = __decorate([ (0, common_1.Module)({}) ], JwtAuthModule); exports.JwtAuthModule = JwtAuthModule; //# sourceMappingURL=jwt.auth.module.js.map