1 | "use strict";
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | 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;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | var PassportModule_1;
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.PassportModule = void 0;
|
11 | const common_1 = require("@nestjs/common");
|
12 | const auth_module_options_1 = require("./interfaces/auth-module.options");
|
13 | let PassportModule = exports.PassportModule = PassportModule_1 = class PassportModule {
|
14 | static register(options) {
|
15 | return {
|
16 | module: PassportModule_1,
|
17 | providers: [{ provide: auth_module_options_1.AuthModuleOptions, useValue: options }],
|
18 | exports: [auth_module_options_1.AuthModuleOptions]
|
19 | };
|
20 | }
|
21 | static registerAsync(options) {
|
22 | return {
|
23 | module: PassportModule_1,
|
24 | imports: options.imports || [],
|
25 | providers: this.createAsyncProviders(options),
|
26 | exports: [auth_module_options_1.AuthModuleOptions]
|
27 | };
|
28 | }
|
29 | static createAsyncProviders(options) {
|
30 | if (options.useExisting || options.useFactory) {
|
31 | return [this.createAsyncOptionsProvider(options)];
|
32 | }
|
33 | return [
|
34 | this.createAsyncOptionsProvider(options),
|
35 | {
|
36 | provide: options.useClass,
|
37 | useClass: options.useClass
|
38 | }
|
39 | ];
|
40 | }
|
41 | static createAsyncOptionsProvider(options) {
|
42 | if (options.useFactory) {
|
43 | return {
|
44 | provide: auth_module_options_1.AuthModuleOptions,
|
45 | useFactory: options.useFactory,
|
46 | inject: options.inject || []
|
47 | };
|
48 | }
|
49 | return {
|
50 | provide: auth_module_options_1.AuthModuleOptions,
|
51 | useFactory: async (optionsFactory) => await optionsFactory.createAuthOptions(),
|
52 | inject: [options.useExisting || options.useClass]
|
53 | };
|
54 | }
|
55 | };
|
56 | exports.PassportModule = PassportModule = PassportModule_1 = __decorate([
|
57 | (0, common_1.Module)({})
|
58 | ], PassportModule);
|