@hichchi/nest-auth 0.0.1 → 0.0.3

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 (112) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +782 -1567
  3. package/auth.module.js +50 -47
  4. package/auth.module.js.map +1 -1
  5. package/constants.js +7 -4
  6. package/constants.js.map +1 -1
  7. package/controllers/auth.controller.js +148 -145
  8. package/controllers/auth.controller.js.map +1 -1
  9. package/controllers/index.js +4 -1
  10. package/controllers/index.js.map +1 -1
  11. package/decorators/auth-info.decorator.js +6 -3
  12. package/decorators/auth-info.decorator.js.map +1 -1
  13. package/decorators/current-user.decorator.js +6 -3
  14. package/decorators/current-user.decorator.js.map +1 -1
  15. package/decorators/index.js +9 -6
  16. package/decorators/index.js.map +1 -1
  17. package/decorators/permission.decorator.js +8 -4
  18. package/decorators/permission.decorator.js.map +1 -1
  19. package/decorators/roles.decorator.js +8 -4
  20. package/decorators/roles.decorator.js.map +1 -1
  21. package/decorators/socket-id.decorator.js +6 -3
  22. package/decorators/socket-id.decorator.js.map +1 -1
  23. package/decorators/subdomain.decorator.js +11 -8
  24. package/decorators/subdomain.decorator.js.map +1 -1
  25. package/dtos/email-verify.dto.js +17 -14
  26. package/dtos/email-verify.dto.js.map +1 -1
  27. package/dtos/get-auth-response.dto.js +13 -10
  28. package/dtos/get-auth-response.dto.js.map +1 -1
  29. package/dtos/index.js +14 -11
  30. package/dtos/index.js.map +1 -1
  31. package/dtos/refresh-token.dto.js +13 -10
  32. package/dtos/refresh-token.dto.js.map +1 -1
  33. package/dtos/request-reset.dto.js +12 -9
  34. package/dtos/request-reset.dto.js.map +1 -1
  35. package/dtos/resend-email-verify.dto.js +12 -9
  36. package/dtos/resend-email-verify.dto.js.map +1 -1
  37. package/dtos/reset-password-token-verify.dto.js +13 -10
  38. package/dtos/reset-password-token-verify.dto.js.map +1 -1
  39. package/dtos/reset-password.dto.js +16 -13
  40. package/dtos/reset-password.dto.js.map +1 -1
  41. package/dtos/sign-in.dto.js +21 -18
  42. package/dtos/sign-in.dto.js.map +1 -1
  43. package/dtos/sign-up.dto.js +26 -23
  44. package/dtos/sign-up.dto.js.map +1 -1
  45. package/dtos/update-password.dto.js +15 -12
  46. package/dtos/update-password.dto.js.map +1 -1
  47. package/dtos/view-user.dto.js +5 -1
  48. package/dtos/view-user.dto.js.map +1 -1
  49. package/extractors/cookie-extractor.js +6 -3
  50. package/extractors/cookie-extractor.js.map +1 -1
  51. package/extractors/index.js +4 -1
  52. package/extractors/index.js.map +1 -1
  53. package/guards/google-auth.guard.js +24 -21
  54. package/guards/google-auth.guard.js.map +1 -1
  55. package/guards/index.js +8 -5
  56. package/guards/index.js.map +1 -1
  57. package/guards/jwt-auth.guard.js +43 -40
  58. package/guards/jwt-auth.guard.js.map +1 -1
  59. package/guards/local-auth.guard.js +15 -12
  60. package/guards/local-auth.guard.js.map +1 -1
  61. package/guards/permission.guard.js +15 -12
  62. package/guards/permission.guard.js.map +1 -1
  63. package/guards/role.guard.js +15 -12
  64. package/guards/role.guard.js.map +1 -1
  65. package/index.js +18 -13
  66. package/index.js.map +1 -1
  67. package/interfaces/auth-options.interface.js +2 -1
  68. package/interfaces/auth-user.type.js +2 -1
  69. package/interfaces/cache-user.interfaces.js +2 -1
  70. package/interfaces/index.js +9 -6
  71. package/interfaces/index.js.map +1 -1
  72. package/interfaces/token-data.interface.js +2 -1
  73. package/interfaces/user-extra.interfaces.js +2 -1
  74. package/interfaces/user-service.interface.d.ts +1 -1
  75. package/interfaces/user-service.interface.js +2 -1
  76. package/package.json +8 -7
  77. package/pipes/index.js +4 -1
  78. package/pipes/index.js.map +1 -1
  79. package/pipes/override-sign-up-dto.pipe.js +16 -13
  80. package/pipes/override-sign-up-dto.pipe.js.map +1 -1
  81. package/providers/index.js +4 -1
  82. package/providers/index.js.map +1 -1
  83. package/providers/user-service.provider.js +2 -1
  84. package/readme-top.md +24 -24
  85. package/services/auth.service.js +142 -136
  86. package/services/auth.service.js.map +1 -1
  87. package/services/encryption.service.js +18 -15
  88. package/services/encryption.service.js.map +1 -1
  89. package/services/index.js +6 -3
  90. package/services/index.js.map +1 -1
  91. package/services/jwt-token.service.js +14 -11
  92. package/services/jwt-token.service.js.map +1 -1
  93. package/services/token-verify.service.js +10 -7
  94. package/services/token-verify.service.js.map +1 -1
  95. package/services/user-cache.service.js +16 -13
  96. package/services/user-cache.service.js.map +1 -1
  97. package/strategies/google.strategy.js +16 -13
  98. package/strategies/google.strategy.js.map +1 -1
  99. package/strategies/index.js +6 -3
  100. package/strategies/index.js.map +1 -1
  101. package/strategies/jwt.strategy.js +29 -26
  102. package/strategies/jwt.strategy.js.map +1 -1
  103. package/strategies/local.strategy.js +20 -17
  104. package/strategies/local.strategy.js.map +1 -1
  105. package/tokens.js +5 -2
  106. package/tokens.js.map +1 -1
  107. package/utils/config-validation.js +22 -17
  108. package/utils/config-validation.js.map +1 -1
  109. package/utils/generate-auth-user.js +7 -4
  110. package/utils/generate-auth-user.js.map +1 -1
  111. package/utils/index.js +5 -2
  112. package/utils/index.js.map +1 -1
@@ -1,6 +1,9 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import { IsNotEmpty, ValidateIf } from "class-validator";
3
- import { Dto } from "@hichchi/nest-core";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SignUpDto = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const class_validator_1 = require("class-validator");
6
+ const nest_core_1 = require("@hichchi/nest-core");
4
7
  /**
5
8
  * Data Transfer Object for user sign up.
6
9
  * This class is used to encapsulate the required user information
@@ -43,30 +46,30 @@ let SignUpDto = class SignUpDto {
43
46
  */
44
47
  password;
45
48
  };
46
- __decorate([
47
- IsNotEmpty(),
48
- __metadata("design:type", String)
49
+ exports.SignUpDto = SignUpDto;
50
+ tslib_1.__decorate([
51
+ (0, class_validator_1.IsNotEmpty)(),
52
+ tslib_1.__metadata("design:type", String)
49
53
  ], SignUpDto.prototype, "firstName", void 0);
50
- __decorate([
51
- IsNotEmpty(),
52
- __metadata("design:type", String)
54
+ tslib_1.__decorate([
55
+ (0, class_validator_1.IsNotEmpty)(),
56
+ tslib_1.__metadata("design:type", String)
53
57
  ], SignUpDto.prototype, "lastName", void 0);
54
- __decorate([
55
- IsNotEmpty(),
56
- ValidateIf(({ email }) => !email),
57
- __metadata("design:type", String)
58
+ tslib_1.__decorate([
59
+ (0, class_validator_1.IsNotEmpty)(),
60
+ (0, class_validator_1.ValidateIf)(({ email }) => !email),
61
+ tslib_1.__metadata("design:type", String)
58
62
  ], SignUpDto.prototype, "username", void 0);
59
- __decorate([
60
- IsNotEmpty(),
61
- ValidateIf(({ username }) => !username),
62
- __metadata("design:type", String)
63
+ tslib_1.__decorate([
64
+ (0, class_validator_1.IsNotEmpty)(),
65
+ (0, class_validator_1.ValidateIf)(({ username }) => !username),
66
+ tslib_1.__metadata("design:type", String)
63
67
  ], SignUpDto.prototype, "email", void 0);
64
- __decorate([
65
- IsNotEmpty(),
66
- __metadata("design:type", String)
68
+ tslib_1.__decorate([
69
+ (0, class_validator_1.IsNotEmpty)(),
70
+ tslib_1.__metadata("design:type", String)
67
71
  ], SignUpDto.prototype, "password", void 0);
68
- SignUpDto = __decorate([
69
- Dto()
72
+ exports.SignUpDto = SignUpDto = tslib_1.__decorate([
73
+ (0, nest_core_1.Dto)()
70
74
  ], SignUpDto);
71
- export { SignUpDto };
72
75
  //# sourceMappingURL=sign-up.dto.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sign-up.dto.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/dtos/sign-up.dto.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAGzC;;;;;;GAMG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAS;IAClB;;;;OAIG;IAEH,SA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QAAQ,CAAC;;wCACzB;AASf;IADC,IAAA,4BAAU,GAAE;;2CACI;oBA5CR,SAAS;IADrB,IAAA,eAAG,GAAE;GACO,SAAS,CA6CrB"}
@@ -1,6 +1,9 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import { IsNotEmpty } from "class-validator";
3
- import { Dto } from "@hichchi/nest-core";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UpdatePasswordDto = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const class_validator_1 = require("class-validator");
6
+ const nest_core_1 = require("@hichchi/nest-core");
4
7
  /**
5
8
  * Data Transfer Object for updating a user's password.
6
9
  * This class is used to encapsulate the old and new passwords
@@ -24,16 +27,16 @@ let UpdatePasswordDto = class UpdatePasswordDto {
24
27
  */
25
28
  newPassword;
26
29
  };
27
- __decorate([
28
- IsNotEmpty(),
29
- __metadata("design:type", String)
30
+ exports.UpdatePasswordDto = UpdatePasswordDto;
31
+ tslib_1.__decorate([
32
+ (0, class_validator_1.IsNotEmpty)(),
33
+ tslib_1.__metadata("design:type", String)
30
34
  ], UpdatePasswordDto.prototype, "oldPassword", void 0);
31
- __decorate([
32
- IsNotEmpty(),
33
- __metadata("design:type", String)
35
+ tslib_1.__decorate([
36
+ (0, class_validator_1.IsNotEmpty)(),
37
+ tslib_1.__metadata("design:type", String)
34
38
  ], UpdatePasswordDto.prototype, "newPassword", void 0);
35
- UpdatePasswordDto = __decorate([
36
- Dto()
39
+ exports.UpdatePasswordDto = UpdatePasswordDto = tslib_1.__decorate([
40
+ (0, nest_core_1.Dto)()
37
41
  ], UpdatePasswordDto);
38
- export { UpdatePasswordDto };
39
42
  //# sourceMappingURL=update-password.dto.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"update-password.dto.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/dtos/update-password.dto.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAGzC;;;;;;GAMG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC1B;;;;;OAKG;IAEH,WAAW,CAAS;IAEpB;;;;;OAKG;IAEH,WAAW,CAAS;CACvB,CAAA;AAVG;IADC,UAAU,EAAE;;sDACO;AASpB;IADC,UAAU,EAAE;;sDACO;AAjBX,iBAAiB;IAD7B,GAAG,EAAE;GACO,iBAAiB,CAkB7B"}
1
+ {"version":3,"file":"update-password.dto.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/dtos/update-password.dto.ts"],"names":[],"mappings":";;;;AAAA,qDAA6C;AAC7C,kDAAyC;AAGzC;;;;;;GAMG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC1B;;;;;OAKG;IAEH,WAAW,CAAS;IAEpB;;;;;OAKG;IAEH,WAAW,CAAS;CACvB,CAAA;AAlBY,8CAAiB;AAQ1B;IADC,IAAA,4BAAU,GAAE;;sDACO;AASpB;IADC,IAAA,4BAAU,GAAE;;sDACO;4BAjBX,iBAAiB;IAD7B,IAAA,eAAG,GAAE;GACO,iBAAiB,CAkB7B"}
@@ -1,9 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ViewUserDto = void 0;
1
4
  /**
2
5
  * A Data Transfer Object (`DTO`) class used for viewing user data.
3
6
  * This class ensures that the user data is formatted and structured for output or display purposes.
4
7
  * Implements the {@link IViewDto} interface for standardized data formatting operations.
5
8
  */
6
- export class ViewUserDto {
9
+ class ViewUserDto {
7
10
  /**
8
11
  * Formats a user entity for output or display purposes.
9
12
  *
@@ -22,4 +25,5 @@ export class ViewUserDto {
22
25
  return user;
23
26
  }
24
27
  }
28
+ exports.ViewUserDto = ViewUserDto;
25
29
  //# sourceMappingURL=view-user.dto.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"view-user.dto.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/dtos/view-user.dto.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,OAAO,WAAW;IACpB;;;;;;;;;OASG;IACH,aAAa,CAAC,IAAkB;QAC5B,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
1
+ {"version":3,"file":"view-user.dto.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/dtos/view-user.dto.ts"],"names":[],"mappings":";;;AAGA;;;;GAIG;AACH,MAAa,WAAW;IACpB;;;;;;;;;OASG;IACH,aAAa,CAAC,IAAkB;QAC5B,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAnBD,kCAmBC"}
@@ -1,4 +1,7 @@
1
- import { ACCESS_TOKEN_COOKIE_NAME } from "../constants";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cookieExtractor = cookieExtractor;
4
+ const constants_1 = require("../constants");
2
5
  /**
3
6
  * Extract access token from the request cookies
4
7
  *
@@ -16,8 +19,8 @@ import { ACCESS_TOKEN_COOKIE_NAME } from "../constants";
16
19
  * @see {@link JwtAuthGuard} Guard that uses this extractor for authentication
17
20
  * @see {@link AuthMethod.COOKIE} Authentication method that uses cookies
18
21
  */
19
- export function cookieExtractor(request) {
22
+ function cookieExtractor(request) {
20
23
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
21
- return request?.signedCookies[ACCESS_TOKEN_COOKIE_NAME] || null;
24
+ return request?.signedCookies[constants_1.ACCESS_TOKEN_COOKIE_NAME] || null;
22
25
  }
23
26
  //# sourceMappingURL=cookie-extractor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cookie-extractor.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/extractors/cookie-extractor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAExD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC5C,sEAAsE;IACtE,OAAQ,OAAO,EAAE,aAAa,CAAC,wBAAwB,CAAiB,IAAI,IAAI,CAAC;AACrF,CAAC"}
1
+ {"version":3,"file":"cookie-extractor.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/extractors/cookie-extractor.ts"],"names":[],"mappings":";;AAqBA,0CAGC;AAtBD,4CAAwD;AAExD;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,eAAe,CAAC,OAAgB;IAC5C,sEAAsE;IACtE,OAAQ,OAAO,EAAE,aAAa,CAAC,oCAAwB,CAAiB,IAAI,IAAI,CAAC;AACrF,CAAC"}
@@ -1,2 +1,5 @@
1
- export * from "./cookie-extractor";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./cookie-extractor"), exports);
2
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/extractors/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/extractors/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC"}
@@ -1,12 +1,15 @@
1
+ "use strict";
1
2
  // noinspection JSUnusedGlobalSymbols
2
- import { __decorate, __metadata, __param } from "tslib";
3
- import { AuthGuard } from "@nestjs/passport";
4
- import { BadRequestException, Inject, Injectable, InternalServerErrorException, UnauthorizedException, } from "@nestjs/common";
5
- import { AUTH_OPTIONS } from "../tokens";
6
- import * as passport from "passport";
7
- import { AuthEndpoint, AuthErrors, AuthStrategy } from "@hichchi/nest-connector/auth";
8
- import { Errors } from "@hichchi/nest-connector";
9
- import { LoggerService } from "@hichchi/nest-core";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.GoogleAuthGuard = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const passport_1 = require("@nestjs/passport");
7
+ const common_1 = require("@nestjs/common");
8
+ const tokens_1 = require("../tokens");
9
+ const passport = tslib_1.__importStar(require("passport"));
10
+ const auth_1 = require("@hichchi/nest-connector/auth");
11
+ const nest_connector_1 = require("@hichchi/nest-connector");
12
+ const nest_core_1 = require("@hichchi/nest-core");
10
13
  /**
11
14
  * Guard for Google OAuth authentication.
12
15
  *
@@ -31,7 +34,7 @@ import { LoggerService } from "@hichchi/nest-core";
31
34
  * }
32
35
  * ```
33
36
  */
34
- let GoogleAuthGuard = class GoogleAuthGuard extends AuthGuard(AuthStrategy.GOOGLE) {
37
+ let GoogleAuthGuard = class GoogleAuthGuard extends (0, passport_1.AuthGuard)(auth_1.AuthStrategy.GOOGLE) {
35
38
  options;
36
39
  /**
37
40
  * Creates an instance of GoogleAuthGuard.
@@ -60,28 +63,28 @@ let GoogleAuthGuard = class GoogleAuthGuard extends AuthGuard(AuthStrategy.GOOGL
60
63
  if (!this.options.googleAuth?.clientId ||
61
64
  !this.options.googleAuth?.clientSecret ||
62
65
  !this.options.googleAuth?.callbackUrl) {
63
- throw new InternalServerErrorException(Errors.ERROR_404_NOT_IMPLEMENTED);
66
+ throw new common_1.InternalServerErrorException(nest_connector_1.Errors.ERROR_404_NOT_IMPLEMENTED);
64
67
  }
65
68
  const request = context.switchToHttp().getRequest();
66
69
  const response = context.switchToHttp().getResponse();
67
70
  const { state, redirectUrl } = request.query;
68
71
  if (!state && !redirectUrl) {
69
- throw new BadRequestException(AuthErrors.AUTH_400_REDIRECT_URL_REQUIRED);
72
+ throw new common_1.BadRequestException(auth_1.AuthErrors.AUTH_400_REDIRECT_URL_REQUIRED);
70
73
  }
71
74
  const options = { session: false, state: JSON.stringify({ redirectUrl }) };
72
75
  return new Promise((resolve, reject) => {
73
76
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
74
- passport.authenticate(AuthStrategy.GOOGLE, options,
77
+ passport.authenticate(auth_1.AuthStrategy.GOOGLE, options,
75
78
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
76
79
  (error, authUser, _info) => {
77
80
  if (error) {
78
- LoggerService.error(error, this.constructor.name);
79
- reject(new UnauthorizedException(AuthErrors.AUTH_500_SOCIAL_SIGN_IN));
81
+ nest_core_1.LoggerService.error(error, this.constructor.name);
82
+ reject(new common_1.UnauthorizedException(auth_1.AuthErrors.AUTH_500_SOCIAL_SIGN_IN));
80
83
  return;
81
84
  }
82
- const isCallback = request.url.includes(AuthEndpoint.GOOGLE_CALLBACK);
85
+ const isCallback = request.url.includes(auth_1.AuthEndpoint.GOOGLE_CALLBACK);
83
86
  if (!authUser && isCallback) {
84
- return reject(new UnauthorizedException(AuthErrors.AUTH_500_SOCIAL_SIGN_IN));
87
+ return reject(new common_1.UnauthorizedException(auth_1.AuthErrors.AUTH_500_SOCIAL_SIGN_IN));
85
88
  }
86
89
  if (authUser) {
87
90
  request.authInfo = authUser;
@@ -91,10 +94,10 @@ let GoogleAuthGuard = class GoogleAuthGuard extends AuthGuard(AuthStrategy.GOOGL
91
94
  });
92
95
  }
93
96
  };
94
- GoogleAuthGuard = __decorate([
95
- Injectable(),
96
- __param(0, Inject(AUTH_OPTIONS)),
97
- __metadata("design:paramtypes", [Object])
97
+ exports.GoogleAuthGuard = GoogleAuthGuard;
98
+ exports.GoogleAuthGuard = GoogleAuthGuard = tslib_1.__decorate([
99
+ (0, common_1.Injectable)(),
100
+ tslib_1.__param(0, (0, common_1.Inject)(tokens_1.AUTH_OPTIONS)),
101
+ tslib_1.__metadata("design:paramtypes", [Object])
98
102
  ], GoogleAuthGuard);
99
- export { GoogleAuthGuard };
100
103
  //# sourceMappingURL=google-auth.guard.js.map
@@ -1 +1 @@
1
- {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th.guard";
4
- export * from "./permission.guard";
5
- export * from "./role.guard";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./local-auth.guard"), exports);
5
+ tslib_1.__exportStar(require("./jwt-auth.guard"), exports);
6
+ tslib_1.__exportStar(require("./google-auth.guard"), exports);
7
+ tslib_1.__exportStar(require("./permission.guard"), exports);
8
+ tslib_1.__exportStar(require("./role.guard"), exports);
6
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/guards/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/guards/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,2DAAiC;AACjC,8DAAoC;AACpC,6DAAmC;AACnC,uDAA6B"}
@@ -1,16 +1,19 @@
1
+ "use strict";
1
2
  // noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols,ExceptionCaughtLocallyJS
2
- import { __decorate, __metadata, __param } from "tslib";
3
- import { Inject, Injectable, UnauthorizedException } from "@nestjs/common";
4
- import { AuthGuard } from "@nestjs/passport";
5
- import { ExtractJwt } from "passport-jwt";
6
- import { AUTH_OPTIONS } from "../tokens";
7
- import { AuthService, UserCacheService } from "../services";
8
- import { cookieExtractor } from "../extractors";
9
- import { v4 as uuid } from "uuid";
10
- import { LoggerService } from "@hichchi/nest-core";
11
- import { AuthErrors, AuthMethod, AuthStrategy } from "@hichchi/nest-connector/auth";
12
- import { SECOND_IN_MS } from "@hichchi/nest-connector";
13
- import { ACCESS_TOKEN_COOKIE_NAME, REFRESH_TOKEN_COOKIE_NAME } from "../constants";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.JwtAuthGuard = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const passport_1 = require("@nestjs/passport");
8
+ const passport_jwt_1 = require("passport-jwt");
9
+ const tokens_1 = require("../tokens");
10
+ const services_1 = require("../services");
11
+ const extractors_1 = require("../extractors");
12
+ const uuid_1 = require("uuid");
13
+ const nest_core_1 = require("@hichchi/nest-core");
14
+ const auth_1 = require("@hichchi/nest-connector/auth");
15
+ const nest_connector_1 = require("@hichchi/nest-connector");
16
+ const constants_1 = require("../constants");
14
17
  /**
15
18
  * Guard for JWT authentication.
16
19
  *
@@ -31,7 +34,7 @@ import { ACCESS_TOKEN_COOKIE_NAME, REFRESH_TOKEN_COOKIE_NAME } from "../constant
31
34
  * }
32
35
  * ```
33
36
  */
34
- let JwtAuthGuard = class JwtAuthGuard extends AuthGuard(AuthStrategy.JWT) {
37
+ let JwtAuthGuard = class JwtAuthGuard extends (0, passport_1.AuthGuard)(auth_1.AuthStrategy.JWT) {
35
38
  options;
36
39
  authService;
37
40
  cacheService;
@@ -64,21 +67,21 @@ let JwtAuthGuard = class JwtAuthGuard extends AuthGuard(AuthStrategy.JWT) {
64
67
  const request = context.switchToHttp().getRequest();
65
68
  const response = context.switchToHttp().getResponse();
66
69
  try {
67
- const accessToken = this.options.authMethod === AuthMethod.COOKIE
68
- ? ExtractJwt.fromExtractors([cookieExtractor])(request)
69
- : ExtractJwt.fromAuthHeaderAsBearerToken()(request);
70
+ const accessToken = this.options.authMethod === auth_1.AuthMethod.COOKIE
71
+ ? passport_jwt_1.ExtractJwt.fromExtractors([extractors_1.cookieExtractor])(request)
72
+ : passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken()(request);
70
73
  if (accessToken) {
71
74
  return await this.activate(context);
72
75
  }
73
- if (this.options.authMethod === AuthMethod.COOKIE && this.options.cookies) {
76
+ if (this.options.authMethod === auth_1.AuthMethod.COOKIE && this.options.cookies) {
74
77
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
75
- const refreshToken = request.signedCookies[REFRESH_TOKEN_COOKIE_NAME];
78
+ const refreshToken = request.signedCookies[constants_1.REFRESH_TOKEN_COOKIE_NAME];
76
79
  if (!refreshToken) {
77
- throw new UnauthorizedException(AuthErrors.AUTH_401_NOT_LOGGED_IN);
80
+ throw new common_1.UnauthorizedException(auth_1.AuthErrors.AUTH_401_NOT_LOGGED_IN);
78
81
  }
79
82
  const user = await this.authService.getUserByToken(request, refreshToken, true);
80
83
  if (!user) {
81
- throw new UnauthorizedException(AuthErrors.AUTH_401_INVALID_REFRESH_TOKEN);
84
+ throw new common_1.UnauthorizedException(auth_1.AuthErrors.AUTH_401_INVALID_REFRESH_TOKEN);
82
85
  }
83
86
  const tokens = this.authService.generateTokens(user);
84
87
  const cacheUser = (await this.cacheService.getUser(user.id)) ?? {
@@ -87,22 +90,22 @@ let JwtAuthGuard = class JwtAuthGuard extends AuthGuard(AuthStrategy.JWT) {
87
90
  };
88
91
  cacheUser.sessions = cacheUser.sessions.filter(session => session.refreshToken !== refreshToken);
89
92
  cacheUser.sessions.push({
90
- sessionId: uuid(),
93
+ sessionId: (0, uuid_1.v4)(),
91
94
  accessToken: tokens.accessToken,
92
95
  refreshToken: tokens.refreshToken,
93
96
  });
94
97
  await this.cacheService.setUser(cacheUser);
95
98
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
96
- request.signedCookies[ACCESS_TOKEN_COOKIE_NAME] = tokens.accessToken;
97
- response.cookie(ACCESS_TOKEN_COOKIE_NAME, tokens.accessToken, {
98
- maxAge: Number(this.options.jwt.expiresIn) * SECOND_IN_MS,
99
+ request.signedCookies[constants_1.ACCESS_TOKEN_COOKIE_NAME] = tokens.accessToken;
100
+ response.cookie(constants_1.ACCESS_TOKEN_COOKIE_NAME, tokens.accessToken, {
101
+ maxAge: Number(this.options.jwt.expiresIn) * nest_connector_1.SECOND_IN_MS,
99
102
  httpOnly: false,
100
103
  sameSite: this.options.cookies.sameSite,
101
104
  secure: this.options.cookies.secure,
102
105
  signed: true,
103
106
  });
104
- response.cookie(REFRESH_TOKEN_COOKIE_NAME, tokens.refreshToken, {
105
- maxAge: Number(this.options.jwt.refreshExpiresIn) * SECOND_IN_MS,
107
+ response.cookie(constants_1.REFRESH_TOKEN_COOKIE_NAME, tokens.refreshToken, {
108
+ maxAge: Number(this.options.jwt.refreshExpiresIn) * nest_connector_1.SECOND_IN_MS,
106
109
  httpOnly: false,
107
110
  sameSite: this.options.cookies.sameSite,
108
111
  secure: this.options.cookies.secure,
@@ -110,18 +113,18 @@ let JwtAuthGuard = class JwtAuthGuard extends AuthGuard(AuthStrategy.JWT) {
110
113
  });
111
114
  return await this.activate(context);
112
115
  }
113
- throw new UnauthorizedException(AuthErrors.AUTH_401_NOT_LOGGED_IN);
116
+ throw new common_1.UnauthorizedException(auth_1.AuthErrors.AUTH_401_NOT_LOGGED_IN);
114
117
  }
115
118
  catch (error) {
116
- if (this.options.authMethod === AuthMethod.COOKIE) {
117
- response.clearCookie(ACCESS_TOKEN_COOKIE_NAME);
118
- response.clearCookie(REFRESH_TOKEN_COOKIE_NAME);
119
+ if (this.options.authMethod === auth_1.AuthMethod.COOKIE) {
120
+ response.clearCookie(constants_1.ACCESS_TOKEN_COOKIE_NAME);
121
+ response.clearCookie(constants_1.REFRESH_TOKEN_COOKIE_NAME);
119
122
  }
120
- if (error instanceof UnauthorizedException) {
123
+ if (error instanceof common_1.UnauthorizedException) {
121
124
  throw error;
122
125
  }
123
- LoggerService.error(error, this.constructor.name);
124
- throw new UnauthorizedException(AuthErrors.AUTH_401_NOT_LOGGED_IN);
126
+ nest_core_1.LoggerService.error(error, this.constructor.name);
127
+ throw new common_1.UnauthorizedException(auth_1.AuthErrors.AUTH_401_NOT_LOGGED_IN);
125
128
  }
126
129
  }
127
130
  /**
@@ -154,17 +157,17 @@ let JwtAuthGuard = class JwtAuthGuard extends AuthGuard(AuthStrategy.JWT) {
154
157
  handleRequest(error, user, _info) {
155
158
  // You can throw an exception based on either "info" or "error" arguments
156
159
  if (error || !user) {
157
- throw error || new UnauthorizedException(AuthErrors.AUTH_401_INVALID_TOKEN);
160
+ throw error || new common_1.UnauthorizedException(auth_1.AuthErrors.AUTH_401_INVALID_TOKEN);
158
161
  }
159
162
  user.password = null;
160
163
  return user;
161
164
  }
162
165
  };
163
- JwtAuthGuard = __decorate([
164
- Injectable(),
165
- __param(0, Inject(AUTH_OPTIONS)),
166
- __metadata("design:paramtypes", [Object, AuthService,
167
- UserCacheService])
166
+ exports.JwtAuthGuard = JwtAuthGuard;
167
+ exports.JwtAuthGuard = JwtAuthGuard = tslib_1.__decorate([
168
+ (0, common_1.Injectable)(),
169
+ tslib_1.__param(0, (0, common_1.Inject)(tokens_1.AUTH_OPTIONS)),
170
+ tslib_1.__metadata("design:paramtypes", [Object, services_1.AuthService,
171
+ services_1.UserCacheService])
168
172
  ], JwtAuthGuard);
169
- export { JwtAuthGuard };
170
173
  //# sourceMappingURL=jwt-auth.guard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"jwt-auth.guard.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/guards/jwt-auth.guard.ts"],"names":[],"mappings":"AAAA,mFAAmF;;AAEnF,OAAO,EAAoB,MAAM,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD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AgB;GAX1C,YAAY,CAgJxB"}
@@ -1,9 +1,12 @@
1
+ "use strict";
1
2
  // noinspection JSUnusedGlobalSymbols
2
- import { __decorate } from "tslib";
3
- import { AuthGuard } from "@nestjs/passport";
4
- import { Injectable, UnauthorizedException } from "@nestjs/common";
5
- import { AuthErrors, AuthStrategy } from "@hichchi/nest-connector/auth";
6
- import { LoggerService } from "@hichchi/nest-core";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.LocalAuthGuard = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const passport_1 = require("@nestjs/passport");
7
+ const common_1 = require("@nestjs/common");
8
+ const auth_1 = require("@hichchi/nest-connector/auth");
9
+ const nest_core_1 = require("@hichchi/nest-core");
7
10
  /**
8
11
  * Guard for local authentication (username/password).
9
12
  *
@@ -21,7 +24,7 @@ import { LoggerService } from "@hichchi/nest-core";
21
24
  * }
22
25
  * ```
23
26
  */
24
- let LocalAuthGuard = class LocalAuthGuard extends AuthGuard(AuthStrategy.LOCAL) {
27
+ let LocalAuthGuard = class LocalAuthGuard extends (0, passport_1.AuthGuard)(auth_1.AuthStrategy.LOCAL) {
25
28
  /**
26
29
  * Determines if the current request is allowed to proceed.
27
30
  *
@@ -36,7 +39,7 @@ let LocalAuthGuard = class LocalAuthGuard extends AuthGuard(AuthStrategy.LOCAL)
36
39
  canActivate(context) {
37
40
  const { body: { email, username, password }, } = context.switchToHttp().getRequest();
38
41
  if ((!email && !username) || !password) {
39
- throw new UnauthorizedException(AuthErrors.AUTH_401_INVALID_USERNAME_PASSWORD);
42
+ throw new common_1.UnauthorizedException(auth_1.AuthErrors.AUTH_401_INVALID_USERNAME_PASSWORD);
40
43
  }
41
44
  return super.canActivate(context);
42
45
  }
@@ -59,15 +62,15 @@ let LocalAuthGuard = class LocalAuthGuard extends AuthGuard(AuthStrategy.LOCAL)
59
62
  // You can throw an exception based on either "info" or "error" arguments
60
63
  if (error || !user) {
61
64
  if (error)
62
- LoggerService.error(error, this.constructor.name);
63
- throw error || new UnauthorizedException(AuthErrors.AUTH_500_SIGN_IN);
65
+ nest_core_1.LoggerService.error(error, this.constructor.name);
66
+ throw error || new common_1.UnauthorizedException(auth_1.AuthErrors.AUTH_500_SIGN_IN);
64
67
  }
65
68
  user.password = null;
66
69
  return user;
67
70
  }
68
71
  };
69
- LocalAuthGuard = __decorate([
70
- Injectable()
72
+ exports.LocalAuthGuard = LocalAuthGuard;
73
+ exports.LocalAuthGuard = LocalAuthGuard = tslib_1.__decorate([
74
+ (0, common_1.Injectable)()
71
75
  ], LocalAuthGuard);
72
- export { LocalAuthGuard };
73
76
  //# sourceMappingURL=local-auth.guard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"local-auth.guard.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/guards/local-auth.guard.ts"],"names":[],"mappings":"AAAA,qCAAqC;;AAErC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAoB,UAAU,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAErF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAQ,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;;;;;;;;;;;;;;GAgBG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC;IAC7D;;;;;;;;;;OAUG;IACM,WAAW,CAAC,OAAyB;QAC1C,MAAM,EACF,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,GACtC,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACxC,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACrC,MAAM,IAAI,qBAAqB,CAAC,UAAU,CAAC,kCAAkC,CAAC,CAAC;QACnF,CAAC;QACD,OAAO,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AAC;IACtC,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,gGAAgG;IACvF,aAAa,CAAC,KAAc,EAAE,IAAU,EAAE,KAAc;QAC7D,yEAAyE;QACzE,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACjB,IAAI,KAAK;gBAAE,yBAAa,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YAC7D,MAAM,KAAK,IAAI,IAAI,8BAAqB,CAAC,iBAAU,CAAC,gBAAgB,CAAC,CAAC;QAC1E,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAA;AA9CY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;GACA,cAAc,CA8C1B"}
@@ -1,9 +1,12 @@
1
+ "use strict";
1
2
  // noinspection JSUnusedGlobalSymbols
2
- import { __decorate, __metadata } from "tslib";
3
- import { ForbiddenException, Injectable } from "@nestjs/common";
4
- import { Reflector } from "@nestjs/core";
5
- import { AuthErrors, isRoleObject } from "@hichchi/nest-connector/auth";
6
- import { PERMISSION_KEY } from "../decorators";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PermissionGuard = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const core_1 = require("@nestjs/core");
8
+ const auth_1 = require("@hichchi/nest-connector/auth");
9
+ const decorators_1 = require("../decorators");
7
10
  /**
8
11
  * Guard for permission-based authorization.
9
12
  *
@@ -45,7 +48,7 @@ let PermissionGuard = class PermissionGuard {
45
48
  * @throws {ForbiddenException} If the user doesn't have the required permission
46
49
  */
47
50
  canActivate(context) {
48
- const requiredPermission = this.reflector.getAllAndOverride(PERMISSION_KEY, [
51
+ const requiredPermission = this.reflector.getAllAndOverride(decorators_1.PERMISSION_KEY, [
49
52
  context.getHandler(),
50
53
  context.getClass(),
51
54
  ]);
@@ -53,15 +56,15 @@ let PermissionGuard = class PermissionGuard {
53
56
  return true;
54
57
  }
55
58
  const { user } = context.switchToHttp().getRequest();
56
- if (isRoleObject(user.role) && user.role.permissions?.includes(requiredPermission)) {
59
+ if ((0, auth_1.isRoleObject)(user.role) && user.role.permissions?.includes(requiredPermission)) {
57
60
  return true;
58
61
  }
59
- throw new ForbiddenException(AuthErrors.AUTH_403_PERMISSION_FORBIDDEN);
62
+ throw new common_1.ForbiddenException(auth_1.AuthErrors.AUTH_403_PERMISSION_FORBIDDEN);
60
63
  }
61
64
  };
62
- PermissionGuard = __decorate([
63
- Injectable(),
64
- __metadata("design:paramtypes", [Reflector])
65
+ exports.PermissionGuard = PermissionGuard;
66
+ exports.PermissionGuard = PermissionGuard = tslib_1.__decorate([
67
+ (0, common_1.Injectable)(),
68
+ tslib_1.__metadata("design:paramtypes", [core_1.Reflector])
65
69
  ], PermissionGuard);
66
- export { PermissionGuard };
67
70
  //# sourceMappingURL=permission.guard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"permission.guard.js","sourceRoot":"","sources":["../../../../libs/nest-auth/src/guards/permission.guard.ts"],"names":[],"mappings":"AAAA,qCAAqC;;AAErC,OAAO,EAAiC,kBAAkB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAQ,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C;;;;;;;;;;;;;;;;;GAiBG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAMJ;IALpB;;;;OAIG;IACH,YAAoB,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAE5C;;;;;;;;;;;OAWG;IACH,WAAW,CAA4B,OAAyB;QAC5D,MAAM,kBAAkB,GAAM,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAA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