@opensaas/keystone-nextjs-auth 22.2.1 → 23.0.0
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/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# @opensaas-keystone/nextjs-auth
|
2
2
|
|
3
|
+
## 23.0.0
|
4
|
+
|
5
|
+
### Major Changes
|
6
|
+
|
7
|
+
- cedcb30: Upgrade to `@keystone-6/core@2.0.0`
|
8
|
+
|
9
|
+
## 22.2.3
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 415a15d: Fix the session user input so get is used correctly
|
14
|
+
|
15
|
+
## 22.2.2
|
16
|
+
|
17
|
+
### Patch Changes
|
18
|
+
|
19
|
+
- 544ffd8: fix session order
|
20
|
+
|
3
21
|
## 22.2.1
|
4
22
|
|
5
23
|
### Patch Changes
|
@@ -386,13 +386,6 @@ function createAuth({
|
|
386
386
|
}) => {
|
387
387
|
var _req$headers, _req$headers$authoriz;
|
388
388
|
|
389
|
-
const session = await get({
|
390
|
-
req,
|
391
|
-
createContext
|
392
|
-
});
|
393
|
-
const sudoContext = createContext({
|
394
|
-
sudo: true
|
395
|
-
});
|
396
389
|
const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
397
390
|
let nextSession;
|
398
391
|
|
@@ -400,6 +393,10 @@ function createAuth({
|
|
400
393
|
return;
|
401
394
|
}
|
402
395
|
|
396
|
+
const sudoContext = createContext({
|
397
|
+
sudo: true
|
398
|
+
});
|
399
|
+
|
403
400
|
if (((_req$headers = req.headers) === null || _req$headers === void 0 ? void 0 : (_req$headers$authoriz = _req$headers.authorization) === null || _req$headers$authoriz === void 0 ? void 0 : _req$headers$authoriz.split(' ')[0]) === 'Bearer') {
|
404
401
|
nextSession = await jwt.getToken({
|
405
402
|
req,
|
@@ -415,11 +412,21 @@ function createAuth({
|
|
415
412
|
return;
|
416
413
|
}
|
417
414
|
|
418
|
-
|
415
|
+
const reqWithUser = req;
|
416
|
+
reqWithUser.user = {
|
417
|
+
istKey: nextSession.listKey,
|
418
|
+
itemId: nextSession.itemId,
|
419
|
+
data: nextSession.data
|
420
|
+
};
|
421
|
+
const userSession = await get({
|
422
|
+
req: reqWithUser,
|
423
|
+
createContext
|
424
|
+
});
|
425
|
+
return _objectSpread(_objectSpread(_objectSpread({}, userSession), nextSession), {}, {
|
419
426
|
data: nextSession.data,
|
420
427
|
listKey: nextSession.listKey,
|
421
428
|
itemId: nextSession.itemId
|
422
|
-
}
|
429
|
+
});
|
423
430
|
},
|
424
431
|
end: async ({
|
425
432
|
res,
|
@@ -470,9 +477,9 @@ function createAuth({
|
|
470
477
|
publicPages: [...(keystoneConfig.ui.publicPages || []), ...publicPages],
|
471
478
|
getAdditionalFiles: [...(((_keystoneConfig$ui = keystoneConfig.ui) === null || _keystoneConfig$ui === void 0 ? void 0 : _keystoneConfig$ui.getAdditionalFiles) || []), getAdditionalFiles],
|
472
479
|
pageMiddleware: async args => {
|
473
|
-
var
|
480
|
+
var _keystoneConfig$ui2, _keystoneConfig$ui2$p;
|
474
481
|
|
475
|
-
return (
|
482
|
+
return (await pageMiddleware(args)) ?? (keystoneConfig === null || keystoneConfig === void 0 ? void 0 : (_keystoneConfig$ui2 = keystoneConfig.ui) === null || _keystoneConfig$ui2 === void 0 ? void 0 : (_keystoneConfig$ui2$p = _keystoneConfig$ui2.pageMiddleware) === null || _keystoneConfig$ui2$p === void 0 ? void 0 : _keystoneConfig$ui2$p.call(_keystoneConfig$ui2, args));
|
476
483
|
},
|
477
484
|
enableSessionItem: true,
|
478
485
|
isAccessAllowed: async context => {
|
@@ -385,13 +385,6 @@ function createAuth({
|
|
385
385
|
}) => {
|
386
386
|
var _req$headers, _req$headers$authoriz;
|
387
387
|
|
388
|
-
const session = await get({
|
389
|
-
req,
|
390
|
-
createContext
|
391
|
-
});
|
392
|
-
const sudoContext = createContext({
|
393
|
-
sudo: true
|
394
|
-
});
|
395
388
|
const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
396
389
|
let nextSession;
|
397
390
|
|
@@ -399,6 +392,10 @@ function createAuth({
|
|
399
392
|
return;
|
400
393
|
}
|
401
394
|
|
395
|
+
const sudoContext = createContext({
|
396
|
+
sudo: true
|
397
|
+
});
|
398
|
+
|
402
399
|
if (((_req$headers = req.headers) === null || _req$headers === void 0 ? void 0 : (_req$headers$authoriz = _req$headers.authorization) === null || _req$headers$authoriz === void 0 ? void 0 : _req$headers$authoriz.split(' ')[0]) === 'Bearer') {
|
403
400
|
nextSession = await jwt.getToken({
|
404
401
|
req,
|
@@ -414,11 +411,21 @@ function createAuth({
|
|
414
411
|
return;
|
415
412
|
}
|
416
413
|
|
417
|
-
|
414
|
+
const reqWithUser = req;
|
415
|
+
reqWithUser.user = {
|
416
|
+
istKey: nextSession.listKey,
|
417
|
+
itemId: nextSession.itemId,
|
418
|
+
data: nextSession.data
|
419
|
+
};
|
420
|
+
const userSession = await get({
|
421
|
+
req: reqWithUser,
|
422
|
+
createContext
|
423
|
+
});
|
424
|
+
return _objectSpread(_objectSpread(_objectSpread({}, userSession), nextSession), {}, {
|
418
425
|
data: nextSession.data,
|
419
426
|
listKey: nextSession.listKey,
|
420
427
|
itemId: nextSession.itemId
|
421
|
-
}
|
428
|
+
});
|
422
429
|
},
|
423
430
|
end: async ({
|
424
431
|
res,
|
@@ -469,9 +476,9 @@ function createAuth({
|
|
469
476
|
publicPages: [...(keystoneConfig.ui.publicPages || []), ...publicPages],
|
470
477
|
getAdditionalFiles: [...(((_keystoneConfig$ui = keystoneConfig.ui) === null || _keystoneConfig$ui === void 0 ? void 0 : _keystoneConfig$ui.getAdditionalFiles) || []), getAdditionalFiles],
|
471
478
|
pageMiddleware: async args => {
|
472
|
-
var
|
479
|
+
var _keystoneConfig$ui2, _keystoneConfig$ui2$p;
|
473
480
|
|
474
|
-
return (
|
481
|
+
return (await pageMiddleware(args)) ?? (keystoneConfig === null || keystoneConfig === void 0 ? void 0 : (_keystoneConfig$ui2 = keystoneConfig.ui) === null || _keystoneConfig$ui2 === void 0 ? void 0 : (_keystoneConfig$ui2$p = _keystoneConfig$ui2.pageMiddleware) === null || _keystoneConfig$ui2$p === void 0 ? void 0 : _keystoneConfig$ui2$p.call(_keystoneConfig$ui2, args));
|
475
482
|
},
|
476
483
|
enableSessionItem: true,
|
477
484
|
isAccessAllowed: async context => {
|
@@ -353,13 +353,6 @@ function createAuth({
|
|
353
353
|
}) => {
|
354
354
|
var _req$headers, _req$headers$authoriz;
|
355
355
|
|
356
|
-
const session = await get({
|
357
|
-
req,
|
358
|
-
createContext
|
359
|
-
});
|
360
|
-
const sudoContext = createContext({
|
361
|
-
sudo: true
|
362
|
-
});
|
363
356
|
const pathname = url.parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
364
357
|
let nextSession;
|
365
358
|
|
@@ -367,6 +360,10 @@ function createAuth({
|
|
367
360
|
return;
|
368
361
|
}
|
369
362
|
|
363
|
+
const sudoContext = createContext({
|
364
|
+
sudo: true
|
365
|
+
});
|
366
|
+
|
370
367
|
if (((_req$headers = req.headers) === null || _req$headers === void 0 ? void 0 : (_req$headers$authoriz = _req$headers.authorization) === null || _req$headers$authoriz === void 0 ? void 0 : _req$headers$authoriz.split(' ')[0]) === 'Bearer') {
|
371
368
|
nextSession = await getToken({
|
372
369
|
req,
|
@@ -382,11 +379,21 @@ function createAuth({
|
|
382
379
|
return;
|
383
380
|
}
|
384
381
|
|
385
|
-
|
382
|
+
const reqWithUser = req;
|
383
|
+
reqWithUser.user = {
|
384
|
+
istKey: nextSession.listKey,
|
385
|
+
itemId: nextSession.itemId,
|
386
|
+
data: nextSession.data
|
387
|
+
};
|
388
|
+
const userSession = await get({
|
389
|
+
req: reqWithUser,
|
390
|
+
createContext
|
391
|
+
});
|
392
|
+
return _objectSpread(_objectSpread(_objectSpread({}, userSession), nextSession), {}, {
|
386
393
|
data: nextSession.data,
|
387
394
|
listKey: nextSession.listKey,
|
388
395
|
itemId: nextSession.itemId
|
389
|
-
}
|
396
|
+
});
|
390
397
|
},
|
391
398
|
end: async ({
|
392
399
|
res,
|
@@ -437,9 +444,9 @@ function createAuth({
|
|
437
444
|
publicPages: [...(keystoneConfig.ui.publicPages || []), ...publicPages],
|
438
445
|
getAdditionalFiles: [...(((_keystoneConfig$ui = keystoneConfig.ui) === null || _keystoneConfig$ui === void 0 ? void 0 : _keystoneConfig$ui.getAdditionalFiles) || []), getAdditionalFiles],
|
439
446
|
pageMiddleware: async args => {
|
440
|
-
var
|
447
|
+
var _keystoneConfig$ui2, _keystoneConfig$ui2$p;
|
441
448
|
|
442
|
-
return (
|
449
|
+
return (await pageMiddleware(args)) ?? (keystoneConfig === null || keystoneConfig === void 0 ? void 0 : (_keystoneConfig$ui2 = keystoneConfig.ui) === null || _keystoneConfig$ui2 === void 0 ? void 0 : (_keystoneConfig$ui2$p = _keystoneConfig$ui2.pageMiddleware) === null || _keystoneConfig$ui2$p === void 0 ? void 0 : _keystoneConfig$ui2$p.call(_keystoneConfig$ui2, args));
|
443
450
|
},
|
444
451
|
enableSessionItem: true,
|
445
452
|
isAccessAllowed: async context => {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@opensaas/keystone-nextjs-auth",
|
3
|
-
"version": "
|
3
|
+
"version": "23.0.0",
|
4
4
|
"repository": "https://github.com/opensaasau/keystone-nextjs-auth",
|
5
5
|
"license": "MIT",
|
6
6
|
"main": "dist/opensaas-keystone-nextjs-auth.cjs.js",
|
@@ -16,12 +16,12 @@
|
|
16
16
|
"next-auth": "^4.3.4"
|
17
17
|
},
|
18
18
|
"devDependencies": {
|
19
|
-
"@keystone-6/core": "^
|
20
|
-
"react": "^
|
19
|
+
"@keystone-6/core": "^2.0.0",
|
20
|
+
"react": "^18.1.0"
|
21
21
|
},
|
22
22
|
"peerDependencies": {
|
23
|
-
"@keystone-6/core": "^
|
24
|
-
"react": "^
|
23
|
+
"@keystone-6/core": "^2.0.0",
|
24
|
+
"react": "^18.1.0"
|
25
25
|
},
|
26
26
|
"engines": {
|
27
27
|
"node": "^14.13 || >= 16.13"
|
package/src/index.ts
CHANGED
@@ -198,13 +198,13 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
|
|
198
198
|
return {
|
199
199
|
...sessionStrategy,
|
200
200
|
get: async ({ req, createContext }) => {
|
201
|
-
const session = await get({ req, createContext });
|
202
|
-
const sudoContext = createContext({ sudo: true });
|
203
201
|
const pathname = url.parse(req?.url!).pathname!;
|
204
202
|
let nextSession: Session;
|
205
203
|
if (pathname.includes('/api/auth')) {
|
206
204
|
return;
|
207
205
|
}
|
206
|
+
const sudoContext = createContext({ sudo: true });
|
207
|
+
|
208
208
|
if (req.headers?.authorization?.split(' ')[0] === 'Bearer') {
|
209
209
|
nextSession = (await getToken({
|
210
210
|
req,
|
@@ -224,12 +224,21 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
|
|
224
224
|
) {
|
225
225
|
return;
|
226
226
|
}
|
227
|
+
const reqWithUser = req as any;
|
228
|
+
reqWithUser.user = {
|
229
|
+
istKey: nextSession.listKey,
|
230
|
+
itemId: nextSession.itemId,
|
231
|
+
data: nextSession.data,
|
232
|
+
};
|
233
|
+
|
234
|
+
const userSession = await get({ req: reqWithUser, createContext });
|
235
|
+
|
227
236
|
return {
|
237
|
+
...userSession,
|
228
238
|
...nextSession,
|
229
239
|
data: nextSession.data,
|
230
240
|
listKey: nextSession.listKey,
|
231
241
|
itemId: nextSession.itemId,
|
232
|
-
...session,
|
233
242
|
};
|
234
243
|
},
|
235
244
|
end: async ({ res, req, createContext }) => {
|