@next-nest-auth/nestauth 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +166 -0
  3. package/dist/global-exception.filter.d.ts +4 -0
  4. package/dist/global-exception.filter.js +30 -0
  5. package/dist/global-exception.filter.js.map +1 -0
  6. package/dist/http-exception.filter.d.ts +4 -0
  7. package/dist/http-exception.filter.js +37 -0
  8. package/dist/http-exception.filter.js.map +1 -0
  9. package/dist/http.exception.filter.d.ts +4 -0
  10. package/dist/http.exception.filter.js +29 -0
  11. package/dist/http.exception.filter.js.map +1 -0
  12. package/dist/index.d.ts +4 -0
  13. package/dist/index.js +21 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/jwt-auth.guard.d.ts +4 -0
  16. package/dist/jwt-auth.guard.js +18 -0
  17. package/dist/jwt-auth.guard.js.map +1 -0
  18. package/dist/jwt.guard.d.ts +4 -0
  19. package/dist/jwt.guard.js +18 -0
  20. package/dist/jwt.guard.js.map +1 -0
  21. package/dist/jwt.strategy.d.ts +12 -0
  22. package/dist/jwt.strategy.js +37 -0
  23. package/dist/jwt.strategy.js.map +1 -0
  24. package/dist/local-auth.guard.d.ts +4 -0
  25. package/dist/local-auth.guard.js +18 -0
  26. package/dist/local-auth.guard.js.map +1 -0
  27. package/dist/local.srategy.d.ts +9 -0
  28. package/dist/local.srategy.js +33 -0
  29. package/dist/local.srategy.js.map +1 -0
  30. package/dist/local.strategy.d.ts +11 -0
  31. package/dist/local.strategy.js +42 -0
  32. package/dist/local.strategy.js.map +1 -0
  33. package/dist/nestauth/nestauth.controller.d.ts +2 -0
  34. package/dist/nestauth/nestauth.controller.js +17 -0
  35. package/dist/nestauth/nestauth.controller.js.map +1 -0
  36. package/dist/nestauth/nestauth.controller.spec.d.ts +1 -0
  37. package/dist/nestauth/nestauth.controller.spec.js +17 -0
  38. package/dist/nestauth/nestauth.controller.spec.js.map +1 -0
  39. package/dist/nestauth-facebook.guard.d.ts +7 -0
  40. package/dist/nestauth-facebook.guard.js +29 -0
  41. package/dist/nestauth-facebook.guard.js.map +1 -0
  42. package/dist/nestauth-facebook.strategy.d.ts +9 -0
  43. package/dist/nestauth-facebook.strategy.js +45 -0
  44. package/dist/nestauth-facebook.strategy.js.map +1 -0
  45. package/dist/nestauth-google.guard.d.ts +7 -0
  46. package/dist/nestauth-google.guard.js +29 -0
  47. package/dist/nestauth-google.guard.js.map +1 -0
  48. package/dist/nestauth-google.strategy.d.ts +9 -0
  49. package/dist/nestauth-google.strategy.js +44 -0
  50. package/dist/nestauth-google.strategy.js.map +1 -0
  51. package/dist/nestauth-jwt.guard.d.ts +6 -0
  52. package/dist/nestauth-jwt.guard.js +32 -0
  53. package/dist/nestauth-jwt.guard.js.map +1 -0
  54. package/dist/nestauth-jwt.strategy.d.ts +18 -0
  55. package/dist/nestauth-jwt.strategy.js +45 -0
  56. package/dist/nestauth-jwt.strategy.js.map +1 -0
  57. package/dist/nestauth-local.guard.d.ts +4 -0
  58. package/dist/nestauth-local.guard.js +18 -0
  59. package/dist/nestauth-local.guard.js.map +1 -0
  60. package/dist/nestauth-local.strategy.d.ts +11 -0
  61. package/dist/nestauth-local.strategy.js +40 -0
  62. package/dist/nestauth-local.strategy.js.map +1 -0
  63. package/dist/nestauth.controller.d.ts +15 -0
  64. package/dist/nestauth.controller.js +119 -0
  65. package/dist/nestauth.controller.js.map +1 -0
  66. package/dist/nestauth.guard.d.ts +4 -0
  67. package/dist/nestauth.guard.js +18 -0
  68. package/dist/nestauth.guard.js.map +1 -0
  69. package/dist/nestauth.interface.d.ts +32 -0
  70. package/dist/nestauth.interface.js +3 -0
  71. package/dist/nestauth.interface.js.map +1 -0
  72. package/dist/nestauth.module.d.ts +5 -0
  73. package/dist/nestauth.module.js +81 -0
  74. package/dist/nestauth.module.js.map +1 -0
  75. package/dist/nestauth.service.d.ts +13 -0
  76. package/dist/nestauth.service.js +71 -0
  77. package/dist/nestauth.service.js.map +1 -0
  78. package/dist/nestauth.strategy.d.ts +11 -0
  79. package/dist/nestauth.strategy.js +38 -0
  80. package/dist/nestauth.strategy.js.map +1 -0
  81. package/dist/tsconfig.tsbuildinfo +1 -0
  82. package/package.json +61 -0
  83. package/src/http-exception.filter.ts +33 -0
  84. package/src/index.ts +4 -0
  85. package/src/nestauth-facebook.guard.ts +12 -0
  86. package/src/nestauth-facebook.strategy.ts +39 -0
  87. package/src/nestauth-google.guard.ts +12 -0
  88. package/src/nestauth-google.strategy.ts +39 -0
  89. package/src/nestauth-jwt.guard.ts +24 -0
  90. package/src/nestauth-jwt.strategy.ts +27 -0
  91. package/src/nestauth-local.guard.ts +5 -0
  92. package/src/nestauth-local.strategy.ts +26 -0
  93. package/src/nestauth.controller.ts +70 -0
  94. package/src/nestauth.interface.ts +37 -0
  95. package/src/nestauth.module.ts +73 -0
  96. package/src/nestauth.service.ts +65 -0
@@ -0,0 +1,32 @@
1
+ import { Type } from "@nestjs/common";
2
+ export interface NestAuthModuleOptions {
3
+ UserService: Type<NestAuthInterface>;
4
+ jwtSecret: string;
5
+ jwtExpiresIn?: string;
6
+ jwtRefreshTokenExpiresIn?: string;
7
+ }
8
+ export type JwtPayloadType = {
9
+ sub: number;
10
+ name?: string;
11
+ email?: string;
12
+ username?: string;
13
+ role?: string;
14
+ pic?: string;
15
+ macId?: string;
16
+ };
17
+ export type SocialProfileType = {
18
+ id: string;
19
+ email: string;
20
+ firstName: string;
21
+ lastName: string;
22
+ picture: string;
23
+ accessToken: string;
24
+ refreshToken: string;
25
+ };
26
+ export type GoogleProfileType = SocialProfileType;
27
+ export type FacebookProfileType = SocialProfileType;
28
+ export interface NestAuthInterface {
29
+ validateUser(params: any): Promise<JwtPayloadType>;
30
+ google(params: GoogleProfileType): Promise<JwtPayloadType>;
31
+ facebook(params: FacebookProfileType): Promise<JwtPayloadType>;
32
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=nestauth.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nestauth.interface.js","sourceRoot":"","sources":["../src/nestauth.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { DynamicModule } from "@nestjs/common";
2
+ import { NestAuthModuleOptions } from "./nestauth.interface";
3
+ export declare class NestAuthModule {
4
+ static register(options: NestAuthModuleOptions): DynamicModule;
5
+ }
@@ -0,0 +1,81 @@
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 NestAuthModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.NestAuthModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const config_1 = require("@nestjs/config");
13
+ const nestauth_service_1 = require("./nestauth.service");
14
+ const nestauth_controller_1 = require("./nestauth.controller");
15
+ const passport_1 = require("@nestjs/passport");
16
+ const jwt_1 = require("@nestjs/jwt");
17
+ const nestauth_jwt_strategy_1 = require("./nestauth-jwt.strategy");
18
+ const nestauth_local_strategy_1 = require("./nestauth-local.strategy");
19
+ const nestauth_google_strategy_1 = require("./nestauth-google.strategy");
20
+ const nestauth_facebook_strategy_1 = require("./nestauth-facebook.strategy");
21
+ const core_1 = require("@nestjs/core");
22
+ const http_exception_filter_1 = require("./http-exception.filter");
23
+ let NestAuthModule = NestAuthModule_1 = class NestAuthModule {
24
+ static register(options) {
25
+ const UserServiceProvider = {
26
+ provide: "UserService",
27
+ useClass: options.UserService,
28
+ };
29
+ const JwtSecretProvider = {
30
+ provide: "JWT_SECRET",
31
+ useValue: options.jwtSecret || "60s",
32
+ };
33
+ const JwtExpiresInProvider = {
34
+ provide: "JWT_EXPIRES_IN",
35
+ useValue: options.jwtExpiresIn,
36
+ };
37
+ const JwtRefreshTokenExpiresInProvider = {
38
+ provide: "JWT_REFRESH_TOKEN_EXPIRES_IN",
39
+ useValue: options.jwtRefreshTokenExpiresIn,
40
+ };
41
+ return {
42
+ module: NestAuthModule_1,
43
+ imports: [
44
+ jwt_1.JwtModule.registerAsync({
45
+ imports: [],
46
+ inject: [],
47
+ useFactory: async () => ({
48
+ secret: options.jwtSecret,
49
+ signOptions: {
50
+ expiresIn: options.jwtExpiresIn,
51
+ },
52
+ }),
53
+ }),
54
+ ],
55
+ providers: [
56
+ nestauth_service_1.NestAuthService,
57
+ UserServiceProvider,
58
+ nestauth_jwt_strategy_1.NestAuthJwtStrategy,
59
+ nestauth_local_strategy_1.NestAuthLocalStrategy,
60
+ nestauth_google_strategy_1.NestAuthGoogleStrategy,
61
+ nestauth_facebook_strategy_1.NestAuthFacebookStrategy,
62
+ JwtSecretProvider,
63
+ JwtExpiresInProvider,
64
+ JwtRefreshTokenExpiresInProvider,
65
+ {
66
+ provide: core_1.APP_FILTER,
67
+ useClass: http_exception_filter_1.HttpExceptionFilter,
68
+ },
69
+ ],
70
+ exports: [nestauth_service_1.NestAuthService],
71
+ controllers: [nestauth_controller_1.NestAuthController],
72
+ };
73
+ }
74
+ };
75
+ exports.NestAuthModule = NestAuthModule;
76
+ exports.NestAuthModule = NestAuthModule = NestAuthModule_1 = __decorate([
77
+ (0, common_1.Module)({
78
+ imports: [passport_1.PassportModule, config_1.ConfigModule.forRoot({})],
79
+ })
80
+ ], NestAuthModule);
81
+ //# sourceMappingURL=nestauth.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nestauth.module.js","sourceRoot":"","sources":["../src/nestauth.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;AACjE,2CAA8C;AAC9C,yDAAqD;AACrD,+DAA2D;AAE3D,+CAAkD;AAClD,qCAAwC;AACxC,mEAA8D;AAC9D,uEAAkE;AAClE,yEAAoE;AACpE,6EAAwE;AACxE,uCAA0C;AAC1C,mEAA8D;AAKvD,IAAM,cAAc,sBAApB,MAAM,cAAc;IACvB,MAAM,CAAC,QAAQ,CAAC,OAA8B;QAC1C,MAAM,mBAAmB,GAAa;YAClC,OAAO,EAAE,aAAa;YACtB,QAAQ,EAAE,OAAO,CAAC,WAAW;SAChC,CAAC;QAEF,MAAM,iBAAiB,GAAa;YAChC,OAAO,EAAE,YAAY;YACrB,QAAQ,EAAE,OAAO,CAAC,SAAS,IAAI,KAAK;SACvC,CAAC;QAEF,MAAM,oBAAoB,GAAa;YACnC,OAAO,EAAE,gBAAgB;YACzB,QAAQ,EAAE,OAAO,CAAC,YAAY;SACjC,CAAC;QAEF,MAAM,gCAAgC,GAAa;YAC/C,OAAO,EAAE,8BAA8B;YACvC,QAAQ,EAAE,OAAO,CAAC,wBAAwB;SAC7C,CAAC;QAEF,OAAO;YACH,MAAM,EAAE,gBAAc;YACtB,OAAO,EAAE;gBACL,eAAS,CAAC,aAAa,CAAC;oBACpB,OAAO,EAAE,EAAE;oBACX,MAAM,EAAE,EAAE;oBACV,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;wBACrB,MAAM,EAAE,OAAO,CAAC,SAAS;wBACzB,WAAW,EAAE;4BACT,SAAS,EAAE,OAAO,CAAC,YAAY;yBAClC;qBACJ,CAAC;iBACL,CAAC;aACL;YACD,SAAS,EAAE;gBACP,kCAAe;gBACf,mBAAmB;gBACnB,2CAAmB;gBACnB,+CAAqB;gBACrB,iDAAsB;gBACtB,qDAAwB;gBACxB,iBAAiB;gBACjB,oBAAoB;gBACpB,gCAAgC;gBAChC;oBACI,OAAO,EAAE,iBAAU;oBACnB,QAAQ,EAAE,2CAAmB;iBAChC;aACJ;YACD,OAAO,EAAE,CAAC,kCAAe,CAAC;YAC1B,WAAW,EAAE,CAAC,wCAAkB,CAAC;SACpC,CAAC;IACN,CAAC;CACJ,CAAA;AAvDY,wCAAc;yBAAd,cAAc;IAH1B,IAAA,eAAM,EAAC;QACJ,OAAO,EAAE,CAAC,yBAAc,EAAE,qBAAY,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;KACtD,CAAC;GACW,cAAc,CAuD1B"}
@@ -0,0 +1,13 @@
1
+ import { FacebookProfileType, GoogleProfileType, NestAuthInterface } from "./nestauth.interface";
2
+ import { JwtService } from "@nestjs/jwt";
3
+ export declare class NestAuthService {
4
+ private jwtService;
5
+ private readonly userService;
6
+ private readonly jwtExpiresIn;
7
+ private readonly jwtRefreshTokenExpiresIn;
8
+ constructor(jwtService: JwtService, userService: NestAuthInterface, jwtExpiresIn: string, jwtRefreshTokenExpiresIn: string);
9
+ login(user: any): Promise<any>;
10
+ google(user: GoogleProfileType): Promise<any>;
11
+ facebook(user: FacebookProfileType): Promise<any>;
12
+ refreshToken(refreshToken: string): Promise<any>;
13
+ }
@@ -0,0 +1,71 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.NestAuthService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const jwt_1 = require("@nestjs/jwt");
18
+ let NestAuthService = class NestAuthService {
19
+ constructor(jwtService, userService, jwtExpiresIn, jwtRefreshTokenExpiresIn) {
20
+ this.jwtService = jwtService;
21
+ this.userService = userService;
22
+ this.jwtExpiresIn = jwtExpiresIn;
23
+ this.jwtRefreshTokenExpiresIn = jwtRefreshTokenExpiresIn;
24
+ }
25
+ async login(user) {
26
+ return {
27
+ accessToken: this.jwtService.sign(user, {
28
+ expiresIn: this.jwtExpiresIn || "15m",
29
+ }),
30
+ refreshToken: this.jwtService.sign(user, { expiresIn: "7d" }),
31
+ accessTokenExpiresIn: this.jwtExpiresIn || "15m",
32
+ refreshTokenExpiresIn: this.jwtRefreshTokenExpiresIn || "7d",
33
+ };
34
+ }
35
+ async google(user) {
36
+ const payload = await this.userService.google(user);
37
+ if (!payload) {
38
+ throw new common_1.UnauthorizedException("Invalid credentials");
39
+ }
40
+ return this.login(payload);
41
+ }
42
+ async facebook(user) {
43
+ const payload = await this.userService.facebook(user);
44
+ if (!payload) {
45
+ throw new common_1.UnauthorizedException("Invalid credentials");
46
+ }
47
+ return this.login(payload);
48
+ }
49
+ async refreshToken(refreshToken) {
50
+ try {
51
+ const payload = this.jwtService.verify(refreshToken);
52
+ const user = await this.userService.validateUser(payload.id);
53
+ if (!user) {
54
+ throw new common_1.UnauthorizedException("Invalid or expired refresh token");
55
+ }
56
+ return this.login(user);
57
+ }
58
+ catch (err) {
59
+ throw new common_1.UnauthorizedException("Invalid or expired refresh token");
60
+ }
61
+ }
62
+ };
63
+ exports.NestAuthService = NestAuthService;
64
+ exports.NestAuthService = NestAuthService = __decorate([
65
+ (0, common_1.Injectable)(),
66
+ __param(1, (0, common_1.Inject)("UserService")),
67
+ __param(2, (0, common_1.Inject)("JWT_EXPIRES_IN")),
68
+ __param(3, (0, common_1.Inject)("JWT_REFRESH_TOKEN_EXPIRES_IN")),
69
+ __metadata("design:paramtypes", [jwt_1.JwtService, Object, String, String])
70
+ ], NestAuthService);
71
+ //# sourceMappingURL=nestauth.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nestauth.service.js","sourceRoot":"","sources":["../src/nestauth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAO3E,qCAAyC;AAGlC,IAAM,eAAe,GAArB,MAAM,eAAe;IACxB,YACY,UAAsB,EACU,WAA8B,EAC3B,YAAoB,EAE9C,wBAAgC;QAJzC,eAAU,GAAV,UAAU,CAAY;QACU,gBAAW,GAAX,WAAW,CAAmB;QAC3B,iBAAY,GAAZ,YAAY,CAAQ;QAE9C,6BAAwB,GAAxB,wBAAwB,CAAQ;IAClD,CAAC;IAEJ,KAAK,CAAC,KAAK,CAAC,IAAS;QACjB,OAAO;YACH,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE;gBACpC,SAAS,EAAE,IAAI,CAAC,YAAY,IAAI,KAAK;aACxC,CAAC;YACF,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;YAC7D,oBAAoB,EAAE,IAAI,CAAC,YAAY,IAAI,KAAK;YAChD,qBAAqB,EAAE,IAAI,CAAC,wBAAwB,IAAI,IAAI;SAC/D,CAAC;IACN,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAuB;QAChC,MAAM,OAAO,GAAmB,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEpE,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,IAAI,8BAAqB,CAAC,qBAAqB,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAyB;QACpC,MAAM,OAAO,GAAmB,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEtE,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,IAAI,8BAAqB,CAAC,qBAAqB,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,YAAoB;QACnC,IAAI,CAAC;YACD,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YACrD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC7D,IAAI,CAAC,IAAI,EAAE,CAAC;gBACR,MAAM,IAAI,8BAAqB,CAC3B,kCAAkC,CACrC,CAAC;YACN,CAAC;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,IAAI,8BAAqB,CAAC,kCAAkC,CAAC,CAAC;QACxE,CAAC;IACL,CAAC;CACJ,CAAA;AAtDY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAIJ,WAAA,IAAA,eAAM,EAAC,aAAa,CAAC,CAAA;IACrB,WAAA,IAAA,eAAM,EAAC,gBAAgB,CAAC,CAAA;IACxB,WAAA,IAAA,eAAM,EAAC,8BAA8B,CAAC,CAAA;qCAHnB,gBAAU;GAFzB,eAAe,CAsD3B"}
@@ -0,0 +1,11 @@
1
+ import { Strategy } from "passport-custom";
2
+ import { NestAuthInterface } from "./nestauth.interface";
3
+ declare const NestAuthStrategy_base: new () => Strategy & {
4
+ validate(...args: any[]): unknown;
5
+ };
6
+ export declare class NestAuthStrategy extends NestAuthStrategy_base {
7
+ private readonly userService;
8
+ constructor(userService: NestAuthInterface);
9
+ validate(req: Request): Promise<any>;
10
+ }
11
+ export {};
@@ -0,0 +1,38 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.NestAuthStrategy = void 0;
16
+ const passport_1 = require("@nestjs/passport");
17
+ const passport_custom_1 = require("passport-custom");
18
+ const common_1 = require("@nestjs/common");
19
+ let NestAuthStrategy = class NestAuthStrategy extends (0, passport_1.PassportStrategy)(passport_custom_1.Strategy, "nestauth") {
20
+ constructor(userService) {
21
+ super();
22
+ this.userService = userService;
23
+ }
24
+ async validate(req) {
25
+ const user = await this.userService.validateUser(req.body);
26
+ if (!user) {
27
+ throw new common_1.UnauthorizedException("Invalid credentials");
28
+ }
29
+ return user;
30
+ }
31
+ };
32
+ exports.NestAuthStrategy = NestAuthStrategy;
33
+ exports.NestAuthStrategy = NestAuthStrategy = __decorate([
34
+ (0, common_1.Injectable)(),
35
+ __param(0, (0, common_1.Inject)("UserService")),
36
+ __metadata("design:paramtypes", [Object])
37
+ ], NestAuthStrategy);
38
+ //# sourceMappingURL=nestauth.strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nestauth.strategy.js","sourceRoot":"","sources":["../src/nestauth.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAoD;AACpD,qDAA2C;AAC3C,2CAA2E;AAIpE,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,IAAA,2BAAgB,EAAC,0BAAQ,EAAE,UAAU,CAAC;IACxE,YAC4C,WAA8B;QAEtE,KAAK,EAAE,CAAC;QAFgC,gBAAW,GAAX,WAAW,CAAmB;IAG1E,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,GAAY;QAGvB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAE3D,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,MAAM,IAAI,8BAAqB,CAAC,qBAAqB,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAA;AAlBY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAGJ,WAAA,IAAA,eAAM,EAAC,aAAa,CAAC,CAAA;;GAFjB,gBAAgB,CAkB5B"}