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 JwtModule_1;
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.JwtModule = void 0;
|
11 | const common_1 = require("@nestjs/common");
|
12 | const jwt_constants_1 = require("./jwt.constants");
|
13 | const jwt_providers_1 = require("./jwt.providers");
|
14 | const jwt_service_1 = require("./jwt.service");
|
15 | let JwtModule = JwtModule_1 = class JwtModule {
|
16 | static register(options) {
|
17 | return {
|
18 | module: JwtModule_1,
|
19 | global: options.global,
|
20 | providers: (0, jwt_providers_1.createJwtProvider)(options)
|
21 | };
|
22 | }
|
23 | static registerAsync(options) {
|
24 | return {
|
25 | module: JwtModule_1,
|
26 | global: options.global,
|
27 | imports: options.imports || [],
|
28 | providers: [
|
29 | ...this.createAsyncProviders(options),
|
30 | ...(options.extraProviders ?? [])
|
31 | ]
|
32 | };
|
33 | }
|
34 | static createAsyncProviders(options) {
|
35 | if (options.useExisting || options.useFactory) {
|
36 | return [this.createAsyncOptionsProvider(options)];
|
37 | }
|
38 | return [
|
39 | this.createAsyncOptionsProvider(options),
|
40 | {
|
41 | provide: options.useClass,
|
42 | useClass: options.useClass
|
43 | }
|
44 | ];
|
45 | }
|
46 | static createAsyncOptionsProvider(options) {
|
47 | if (options.useFactory) {
|
48 | return {
|
49 | provide: jwt_constants_1.JWT_MODULE_OPTIONS,
|
50 | useFactory: options.useFactory,
|
51 | inject: options.inject || []
|
52 | };
|
53 | }
|
54 | return {
|
55 | provide: jwt_constants_1.JWT_MODULE_OPTIONS,
|
56 | useFactory: async (optionsFactory) => await optionsFactory.createJwtOptions(),
|
57 | inject: [options.useExisting || options.useClass]
|
58 | };
|
59 | }
|
60 | };
|
61 | exports.JwtModule = JwtModule;
|
62 | exports.JwtModule = JwtModule = JwtModule_1 = __decorate([
|
63 | (0, common_1.Module)({
|
64 | providers: [jwt_service_1.JwtService],
|
65 | exports: [jwt_service_1.JwtService]
|
66 | })
|
67 | ], JwtModule);
|