@lenne.tech/nest-server 9.2.1 → 9.2.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 (66) hide show
  1. package/README.md +1 -2
  2. package/dist/config.env.js +3 -0
  3. package/dist/config.env.js.map +1 -1
  4. package/dist/core/common/helpers/context.helper.d.ts +5 -2
  5. package/dist/core/common/helpers/context.helper.js +14 -8
  6. package/dist/core/common/helpers/context.helper.js.map +1 -1
  7. package/dist/core/common/interfaces/server-options.interface.d.ts +3 -1
  8. package/dist/core/common/pipes/check-input.pipe.js +2 -2
  9. package/dist/core/common/pipes/check-input.pipe.js.map +1 -1
  10. package/dist/core/modules/auth/core-auth.module.js +5 -1
  11. package/dist/core/modules/auth/core-auth.module.js.map +1 -1
  12. package/dist/core/modules/auth/core-auth.resolver.d.ts +6 -6
  13. package/dist/core/modules/auth/core-auth.resolver.js +26 -23
  14. package/dist/core/modules/auth/core-auth.resolver.js.map +1 -1
  15. package/dist/core/modules/auth/guards/auth.guard.js +9 -2
  16. package/dist/core/modules/auth/guards/auth.guard.js.map +1 -1
  17. package/dist/core/modules/auth/inputs/core-auth-sign-in.input.d.ts +1 -0
  18. package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js +6 -1
  19. package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js.map +1 -1
  20. package/dist/core/modules/auth/inputs/core-auth-sign-up.input.d.ts +2 -5
  21. package/dist/core/modules/auth/inputs/core-auth-sign-up.input.js +2 -23
  22. package/dist/core/modules/auth/inputs/core-auth-sign-up.input.js.map +1 -1
  23. package/dist/core/modules/auth/interfaces/core-auth-user.interface.d.ts +2 -2
  24. package/dist/core/modules/auth/interfaces/core-token-data.interface.d.ts +5 -0
  25. package/dist/core/modules/auth/interfaces/core-token-data.interface.js +3 -0
  26. package/dist/core/modules/auth/interfaces/core-token-data.interface.js.map +1 -0
  27. package/dist/core/modules/auth/interfaces/jwt-payload.interface.d.ts +3 -0
  28. package/dist/core/modules/auth/services/core-auth.service.d.ts +11 -9
  29. package/dist/core/modules/auth/services/core-auth.service.js +62 -50
  30. package/dist/core/modules/auth/services/core-auth.service.js.map +1 -1
  31. package/dist/core/modules/auth/strategies/jwt-refresh.strategy.js +1 -10
  32. package/dist/core/modules/auth/strategies/jwt-refresh.strategy.js.map +1 -1
  33. package/dist/core/modules/auth/strategies/jwt.strategy.js +1 -1
  34. package/dist/core/modules/auth/strategies/jwt.strategy.js.map +1 -1
  35. package/dist/core/modules/auth/tokens.decorator.d.ts +1 -0
  36. package/dist/core/modules/auth/tokens.decorator.js +20 -0
  37. package/dist/core/modules/auth/tokens.decorator.js.map +1 -0
  38. package/dist/core/modules/user/core-user.model.d.ts +2 -2
  39. package/dist/core/modules/user/core-user.model.js +0 -6
  40. package/dist/core/modules/user/core-user.model.js.map +1 -1
  41. package/dist/core.module.js +1 -1
  42. package/dist/core.module.js.map +1 -1
  43. package/dist/index.d.ts +4 -2
  44. package/dist/index.js +4 -2
  45. package/dist/index.js.map +1 -1
  46. package/dist/tsconfig.build.tsbuildinfo +1 -1
  47. package/package.json +1 -1
  48. package/src/config.env.ts +3 -0
  49. package/src/core/common/helpers/context.helper.ts +25 -10
  50. package/src/core/common/interfaces/server-options.interface.ts +11 -1
  51. package/src/core/common/pipes/check-input.pipe.ts +2 -2
  52. package/src/core/modules/auth/core-auth.module.ts +5 -1
  53. package/src/core/modules/auth/core-auth.resolver.ts +23 -20
  54. package/src/core/modules/auth/guards/auth.guard.ts +9 -2
  55. package/src/core/modules/auth/inputs/core-auth-sign-in.input.ts +4 -1
  56. package/src/core/modules/auth/inputs/core-auth-sign-up.input.ts +3 -16
  57. package/src/core/modules/auth/interfaces/core-auth-user.interface.ts +3 -6
  58. package/src/core/modules/auth/interfaces/core-token-data.interface.ts +19 -0
  59. package/src/core/modules/auth/interfaces/jwt-payload.interface.ts +3 -0
  60. package/src/core/modules/auth/services/core-auth.service.ts +93 -81
  61. package/src/core/modules/auth/strategies/jwt-refresh.strategy.ts +1 -11
  62. package/src/core/modules/auth/strategies/jwt.strategy.ts +1 -1
  63. package/src/core/modules/auth/tokens.decorator.ts +36 -0
  64. package/src/core/modules/user/core-user.model.ts +5 -11
  65. package/src/core.module.ts +1 -2
  66. package/src/index.ts +4 -2
@@ -0,0 +1,36 @@
1
+ import { createParamDecorator, ExecutionContext } from '@nestjs/common';
2
+ import { GqlExecutionContext } from '@nestjs/graphql';
3
+ import { getContextData } from '../../common/helpers/context.helper';
4
+
5
+ /**
6
+ * Get current tokens
7
+ */
8
+ export const Tokens = createParamDecorator(
9
+ (
10
+ tokenId: 'token' | 'refreshToken' | undefined,
11
+ ctx: ExecutionContext
12
+ ): string | { token: string; refreshToken: string } => {
13
+ // Get prepared context (REST or GraphQL)
14
+ const context = getContextData(ctx);
15
+
16
+ // Get token from cookie or authorization header
17
+ const token =
18
+ context?.request?.cookies?.['token'] ||
19
+ context?.request
20
+ ?.get('Authorization')
21
+ ?.replace(/bearer/i, '')
22
+ .trim();
23
+
24
+ // Refresh token from cookie or authorization header (the authorization header does not distinguish the tokens)
25
+ const refreshToken = context?.request?.cookies?.['refreshToken'] || token;
26
+
27
+ // Set tokens
28
+ const tokens = { token, refreshToken };
29
+
30
+ // Return tokens
31
+ if (tokenId?.length) {
32
+ return tokens[tokenId];
33
+ }
34
+ return tokens;
35
+ }
36
+ );
@@ -3,6 +3,7 @@ import { Prop, raw, Schema as MongooseSchema } from '@nestjs/mongoose';
3
3
  import { IsEmail, IsOptional } from 'class-validator';
4
4
  import { Document } from 'mongoose';
5
5
  import { CorePersistenceModel } from '../../common/models/core-persistence.model';
6
+ import { CoreTokenData } from '../auth/interfaces/core-token-data.interface';
6
7
 
7
8
  export type CoreUserModelDocument = CoreUserModel & Document;
8
9
 
@@ -70,20 +71,13 @@ export abstract class CoreUserModel extends CorePersistenceModel {
70
71
  passwordResetToken: string = undefined;
71
72
 
72
73
  /**
73
- * Hashed refresh JWT
74
- */
75
- @IsOptional()
76
- @Prop()
77
- refreshToken: string = undefined;
78
-
79
- /**
80
- * Refresh tokens for devices
81
- * key: deviceID
82
- * value: hashed JWT
74
+ * Refresh tokens (for devices)
75
+ * key: Token
76
+ * value: TokenData
83
77
  */
84
78
  @IsOptional()
85
79
  @Prop(raw({}))
86
- refreshTokens: Record<string, string> = undefined;
80
+ refreshTokens: Record<string, CoreTokenData> = undefined;
87
81
 
88
82
  /**
89
83
  * Verification token of the user
@@ -68,8 +68,7 @@ export class CoreModule implements NestModule {
68
68
  onConnect: async (connectionParams) => {
69
69
  if (config.graphQl.enableSubscriptionAuth) {
70
70
  // get authToken from authorization header
71
- const authToken: string =
72
- 'Authorization' in connectionParams && connectionParams?.Authorization?.split(' ')[1];
71
+ const authToken: string = connectionParams?.Authorization?.split(' ')[1];
73
72
 
74
73
  if (authToken) {
75
74
  // verify authToken/getJwtPayLoad
package/src/index.ts CHANGED
@@ -81,14 +81,16 @@ export * from './core/modules/auth/guards/roles.guard';
81
81
  export * from './core/modules/auth/inputs/core-auth-sign-in.input';
82
82
  export * from './core/modules/auth/inputs/core-auth-sign-up.input';
83
83
  export * from './core/modules/auth/interfaces/core-auth-user.interface';
84
+ export * from './core/modules/auth/interfaces/core-token-data.interface';
84
85
  export * from './core/modules/auth/interfaces/jwt-payload.interface';
85
86
  export * from './core/modules/auth/services/core-auth.service';
86
87
  export * from './core/modules/auth/services/core-auth-user.service';
88
+ export * from './core/modules/auth/strategies/jwt.strategy';
89
+ export * from './core/modules/auth/strategies/jwt-refresh.strategy';
87
90
  export * from './core/modules/auth/core-auth.model';
88
91
  export * from './core/modules/auth/core-auth.module';
89
92
  export * from './core/modules/auth/core-auth.resolver';
90
- export * from './core/modules/auth/strategies/jwt.strategy';
91
- export * from './core/modules/auth/strategies/jwt-refresh.strategy';
93
+ export * from './core/modules/auth/tokens.decorator';
92
94
 
93
95
  // =====================================================================================================================
94
96
  // Core - Modules - File