UNPKG

@bitloops/bl-boilerplate-infra-nest-auth-passport

Version:
66 lines (65 loc) 2.81 kB
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; import { Module } from '@nestjs/common'; import { PassportModule } from '@nestjs/passport'; import { AuthService } from './auth.service'; import { LocalStrategy } from './local.strategy'; import { UsersService } from './users/users.service'; import { UserRepoPortToken } from './users/user-repo.port'; import { JwtAuthModule } from './jwt/jwt.module'; import { UserPostgresRepository } from './users/user-repo'; import { PostgresModule, } from '@bitloops/bl-boilerplate-infra-postgres'; import { JWTSecret, IntegrationEventBusToken } from './constants'; let AuthModule = AuthModule_1 = class AuthModule { static forRootAsync({ jwtOptions, postgresOptions, integrationEventBus, }) { const jwtSecretProvider = { provide: JWTSecret, useFactory: async (...args) => { if (!jwtOptions.useFactory) { throw new Error('No useFactory function provided'); } return (await jwtOptions.useFactory(...args)).secret; }, inject: jwtOptions.inject, }; const integrationEventBusProvider = { provide: IntegrationEventBusToken, useClass: integrationEventBus, }; return { module: AuthModule_1, imports: [ JwtAuthModule.registerAsync(jwtOptions), PostgresModule.forRootAsync(postgresOptions), PostgresModule.forFeature(`-- DROP TABLE users; CREATE TABLE IF NOT EXISTS users ( "id" UUID, "email" VARCHAR(100) NOT NULL, "password" VARCHAR(100) NOT NULL, "last_login" TIMESTAMP, PRIMARY KEY ("id") );`), ], providers: [jwtSecretProvider, integrationEventBusProvider], exports: [jwtSecretProvider], }; } }; AuthModule = AuthModule_1 = __decorate([ Module({ imports: [PassportModule], providers: [ AuthService, LocalStrategy, UsersService, { provide: UserRepoPortToken, useClass: UserPostgresRepository }, ], exports: [AuthService], }) ], AuthModule); export { AuthModule };