@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.
- package/README.md +1 -2
- package/dist/config.env.js +3 -0
- package/dist/config.env.js.map +1 -1
- package/dist/core/common/helpers/context.helper.d.ts +5 -2
- package/dist/core/common/helpers/context.helper.js +14 -8
- package/dist/core/common/helpers/context.helper.js.map +1 -1
- package/dist/core/common/interfaces/server-options.interface.d.ts +3 -1
- package/dist/core/common/pipes/check-input.pipe.js +2 -2
- package/dist/core/common/pipes/check-input.pipe.js.map +1 -1
- package/dist/core/modules/auth/core-auth.module.js +5 -1
- package/dist/core/modules/auth/core-auth.module.js.map +1 -1
- package/dist/core/modules/auth/core-auth.resolver.d.ts +6 -6
- package/dist/core/modules/auth/core-auth.resolver.js +26 -23
- package/dist/core/modules/auth/core-auth.resolver.js.map +1 -1
- package/dist/core/modules/auth/guards/auth.guard.js +9 -2
- package/dist/core/modules/auth/guards/auth.guard.js.map +1 -1
- package/dist/core/modules/auth/inputs/core-auth-sign-in.input.d.ts +1 -0
- package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js +6 -1
- package/dist/core/modules/auth/inputs/core-auth-sign-in.input.js.map +1 -1
- package/dist/core/modules/auth/inputs/core-auth-sign-up.input.d.ts +2 -5
- package/dist/core/modules/auth/inputs/core-auth-sign-up.input.js +2 -23
- package/dist/core/modules/auth/inputs/core-auth-sign-up.input.js.map +1 -1
- package/dist/core/modules/auth/interfaces/core-auth-user.interface.d.ts +2 -2
- package/dist/core/modules/auth/interfaces/core-token-data.interface.d.ts +5 -0
- package/dist/core/modules/auth/interfaces/core-token-data.interface.js +3 -0
- package/dist/core/modules/auth/interfaces/core-token-data.interface.js.map +1 -0
- package/dist/core/modules/auth/interfaces/jwt-payload.interface.d.ts +3 -0
- package/dist/core/modules/auth/services/core-auth.service.d.ts +11 -9
- package/dist/core/modules/auth/services/core-auth.service.js +62 -50
- package/dist/core/modules/auth/services/core-auth.service.js.map +1 -1
- package/dist/core/modules/auth/strategies/jwt-refresh.strategy.js +1 -10
- package/dist/core/modules/auth/strategies/jwt-refresh.strategy.js.map +1 -1
- package/dist/core/modules/auth/strategies/jwt.strategy.js +1 -1
- package/dist/core/modules/auth/strategies/jwt.strategy.js.map +1 -1
- package/dist/core/modules/auth/tokens.decorator.d.ts +1 -0
- package/dist/core/modules/auth/tokens.decorator.js +20 -0
- package/dist/core/modules/auth/tokens.decorator.js.map +1 -0
- package/dist/core/modules/user/core-user.model.d.ts +2 -2
- package/dist/core/modules/user/core-user.model.js +0 -6
- package/dist/core/modules/user/core-user.model.js.map +1 -1
- package/dist/core.module.js +1 -1
- package/dist/core.module.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/config.env.ts +3 -0
- package/src/core/common/helpers/context.helper.ts +25 -10
- package/src/core/common/interfaces/server-options.interface.ts +11 -1
- package/src/core/common/pipes/check-input.pipe.ts +2 -2
- package/src/core/modules/auth/core-auth.module.ts +5 -1
- package/src/core/modules/auth/core-auth.resolver.ts +23 -20
- package/src/core/modules/auth/guards/auth.guard.ts +9 -2
- package/src/core/modules/auth/inputs/core-auth-sign-in.input.ts +4 -1
- package/src/core/modules/auth/inputs/core-auth-sign-up.input.ts +3 -16
- package/src/core/modules/auth/interfaces/core-auth-user.interface.ts +3 -6
- package/src/core/modules/auth/interfaces/core-token-data.interface.ts +19 -0
- package/src/core/modules/auth/interfaces/jwt-payload.interface.ts +3 -0
- package/src/core/modules/auth/services/core-auth.service.ts +93 -81
- package/src/core/modules/auth/strategies/jwt-refresh.strategy.ts +1 -11
- package/src/core/modules/auth/strategies/jwt.strategy.ts +1 -1
- package/src/core/modules/auth/tokens.decorator.ts +36 -0
- package/src/core/modules/user/core-user.model.ts +5 -11
- package/src/core.module.ts +1 -2
- 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
|
-
*
|
|
74
|
-
|
|
75
|
-
|
|
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,
|
|
80
|
+
refreshTokens: Record<string, CoreTokenData> = undefined;
|
|
87
81
|
|
|
88
82
|
/**
|
|
89
83
|
* Verification token of the user
|
package/src/core.module.ts
CHANGED
|
@@ -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/
|
|
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
|