UNPKG

@katalysttech/auth

Version:

A flexible authentication module for NestJS applications with JWT and refresh token support

89 lines 3.46 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 AuthModule_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthModule = void 0; const common_1 = require("@nestjs/common"); const jwt_1 = require("@nestjs/jwt"); const auth_service_1 = require("./auth.service"); const password_service_1 = require("./services/password.service"); const refresh_token_service_1 = require("./services/refresh-token.service"); let AuthModule = AuthModule_1 = class AuthModule { static register(options) { return { module: AuthModule_1, imports: [ jwt_1.JwtModule.register({ secret: options.jwt.secret, signOptions: { expiresIn: options.jwt.expiresIn }, }), ], providers: [ { provide: 'AUTH_OPTIONS', useValue: options, }, auth_service_1.AuthService, password_service_1.PasswordService, refresh_token_service_1.RefreshTokenService, ], exports: [auth_service_1.AuthService, password_service_1.PasswordService], global: true }; } static forRootAsync(options) { return { module: AuthModule_1, imports: [ jwt_1.JwtModule.register({}), ...(options.imports || []), ], providers: [ ...this.createAsyncProviders(options), auth_service_1.AuthService, password_service_1.PasswordService, refresh_token_service_1.RefreshTokenService, ], exports: [auth_service_1.AuthService, password_service_1.PasswordService], global: true }; } static createAsyncProviders(options) { if (options.useExisting || options.useFactory) { return [this.createAsyncOptionsProvider(options)]; } return [ this.createAsyncOptionsProvider(options), { provide: options.useClass, useClass: options.useClass, }, ]; } static createAsyncOptionsProvider(options) { if (options.useFactory) { return { provide: 'AUTH_OPTIONS', useFactory: options.useFactory, inject: options.inject || [], }; } return { provide: 'AUTH_OPTIONS', useFactory: async (optionsFactory) => await optionsFactory.createAuthOptions(), inject: [options.useClass || options.useExisting], }; } }; exports.AuthModule = AuthModule; exports.AuthModule = AuthModule = AuthModule_1 = __decorate([ (0, common_1.Module)({}) ], AuthModule); //# sourceMappingURL=auth.module.js.map