@lenne.tech/nest-server 10.2.4 → 10.2.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.
- package/dist/core.module.d.ts +1 -0
- package/dist/core.module.js +21 -2
- package/dist/core.module.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core.module.ts +31 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "10.2.
|
|
3
|
+
"version": "10.2.5",
|
|
4
4
|
"description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
package/src/core.module.ts
CHANGED
|
@@ -40,6 +40,26 @@ export class CoreModule implements NestModule {
|
|
|
40
40
|
consumer.apply(graphqlUploadExpress()).forRoutes('graphql');
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Convert array with key value entries to header object
|
|
45
|
+
* e.g. ['Sec-WebSocket-Version', '13', 'Sec-WebSocket-Key', 'Yu4Lewa60jLk41YXcVrw0w==']
|
|
46
|
+
* => {
|
|
47
|
+
* 'Sec-WebSocket-Version': '13',
|
|
48
|
+
* 'Sec-WebSocket-Key': 'Yu4Lewa60jLk41YXcVrw0w==',
|
|
49
|
+
* }
|
|
50
|
+
*/
|
|
51
|
+
static getHeaderFromArray(array): Record<string, string> {
|
|
52
|
+
const result: Record<string, string> = {};
|
|
53
|
+
if (!array.length) {
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
for (let i = 0; i < array.length; i += 2) {
|
|
57
|
+
const key = array[i];
|
|
58
|
+
result[key] = array[i + 1];
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
43
63
|
/**
|
|
44
64
|
* Dynamic module
|
|
45
65
|
* see https://docs.nestjs.com/modules#dynamic-modules
|
|
@@ -78,6 +98,9 @@ export class CoreModule implements NestModule {
|
|
|
78
98
|
// verify authToken/getJwtPayLoad
|
|
79
99
|
const payload = authService.decodeJwt(authToken);
|
|
80
100
|
const user = await authService.validateUser(payload);
|
|
101
|
+
if (!user) {
|
|
102
|
+
throw new UnauthorizedException('No user found for token');
|
|
103
|
+
}
|
|
81
104
|
// the user/jwtPayload object found will be available as context.currentUser/jwtPayload in your GraphQL resolvers
|
|
82
105
|
return { user, headers: connectionParams };
|
|
83
106
|
}
|
|
@@ -91,14 +114,20 @@ export class CoreModule implements NestModule {
|
|
|
91
114
|
const { connectionParams, extra } = context;
|
|
92
115
|
if (config.graphQl.enableSubscriptionAuth) {
|
|
93
116
|
// get authToken from authorization header
|
|
94
|
-
const
|
|
117
|
+
const headers = this.getHeaderFromArray(extra.request?.rawHeaders);
|
|
118
|
+
const authToken: string
|
|
119
|
+
= connectionParams?.Authorization?.split(' ')[1]
|
|
120
|
+
?? headers.Authorization?.split(' ')[1];
|
|
95
121
|
if (authToken) {
|
|
96
122
|
// verify authToken/getJwtPayLoad
|
|
97
123
|
const payload = authService.decodeJwt(authToken);
|
|
98
124
|
const user = await authService.validateUser(payload);
|
|
125
|
+
if (!user) {
|
|
126
|
+
throw new UnauthorizedException('No user found for token');
|
|
127
|
+
}
|
|
99
128
|
// the user/jwtPayload object found will be available as context.currentUser/jwtPayload in your GraphQL resolvers
|
|
100
129
|
extra.user = user;
|
|
101
|
-
extra.
|
|
130
|
+
extra.headers = connectionParams ?? headers;
|
|
102
131
|
return extra;
|
|
103
132
|
}
|
|
104
133
|
|