@opensaas/keystone-nextjs-auth 22.2.0 → 22.2.3

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @opensaas-keystone/nextjs-auth
2
2
 
3
+ ## 22.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 415a15d: Fix the session user input so get is used correctly
8
+
9
+ ## 22.2.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 544ffd8: fix session order
14
+
15
+ ## 22.2.1
16
+
17
+ ### Patch Changes
18
+
19
+ - 8599b89: remove global prisma client as it is not required
20
+
3
21
  ## 22.2.0
4
22
 
5
23
  ### Minor Changes
@@ -168,13 +168,9 @@ import keystoneConfig from '../../../../../keystone';
168
168
  import { PrismaClient } from '.prisma/client';
169
169
  import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
170
170
 
171
- const prisma = global.prisma || PrismaClient
171
+ const keystoneQueryAPI = global.keystoneQueryAPI || createQueryAPI(keystoneConfig, PrismaClient);
172
172
 
173
- if (process.env.NODE_ENV !== 'production') global.prisma = prisma
174
-
175
- const query = global.query || createQueryAPI(keystoneConfig, prisma);
176
-
177
- if (process.env.NODE_ENV !== 'production') global.query = query
173
+ if (process.env.NODE_ENV !== 'production') globalThis.keystoneQueryAPI = keystoneQueryAPI
178
174
 
179
175
  export default getNextAuthPage({
180
176
  autoCreate: <%= autoCreate %>,
@@ -182,7 +178,7 @@ export default getNextAuthPage({
182
178
  listKey: '<%= listKey %>',
183
179
  pages: keystoneConfig.pages,
184
180
  providers: keystoneConfig.providers,
185
- query,
181
+ query: keystoneQueryAPI,
186
182
  resolver: keystoneConfig.resolver,
187
183
  sessionData: '<%= sessionData %>',
188
184
  sessionSecret: '<%= sessionSecret %>',
@@ -390,13 +386,6 @@ function createAuth({
390
386
  }) => {
391
387
  var _req$headers, _req$headers$authoriz;
392
388
 
393
- const session = await get({
394
- req,
395
- createContext
396
- });
397
- const sudoContext = createContext({
398
- sudo: true
399
- });
400
389
  const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
401
390
  let nextSession;
402
391
 
@@ -404,6 +393,10 @@ function createAuth({
404
393
  return;
405
394
  }
406
395
 
396
+ const sudoContext = createContext({
397
+ sudo: true
398
+ });
399
+
407
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') {
408
401
  nextSession = await jwt.getToken({
409
402
  req,
@@ -419,11 +412,21 @@ function createAuth({
419
412
  return;
420
413
  }
421
414
 
422
- return _objectSpread(_objectSpread({}, nextSession), {}, {
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), {}, {
423
426
  data: nextSession.data,
424
427
  listKey: nextSession.listKey,
425
428
  itemId: nextSession.itemId
426
- }, session);
429
+ });
427
430
  },
428
431
  end: async ({
429
432
  res,
@@ -167,13 +167,9 @@ import keystoneConfig from '../../../../../keystone';
167
167
  import { PrismaClient } from '.prisma/client';
168
168
  import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
169
169
 
170
- const prisma = global.prisma || PrismaClient
170
+ const keystoneQueryAPI = global.keystoneQueryAPI || createQueryAPI(keystoneConfig, PrismaClient);
171
171
 
172
- if (process.env.NODE_ENV !== 'production') global.prisma = prisma
173
-
174
- const query = global.query || createQueryAPI(keystoneConfig, prisma);
175
-
176
- if (process.env.NODE_ENV !== 'production') global.query = query
172
+ if (process.env.NODE_ENV !== 'production') globalThis.keystoneQueryAPI = keystoneQueryAPI
177
173
 
178
174
  export default getNextAuthPage({
179
175
  autoCreate: <%= autoCreate %>,
@@ -181,7 +177,7 @@ export default getNextAuthPage({
181
177
  listKey: '<%= listKey %>',
182
178
  pages: keystoneConfig.pages,
183
179
  providers: keystoneConfig.providers,
184
- query,
180
+ query: keystoneQueryAPI,
185
181
  resolver: keystoneConfig.resolver,
186
182
  sessionData: '<%= sessionData %>',
187
183
  sessionSecret: '<%= sessionSecret %>',
@@ -389,13 +385,6 @@ function createAuth({
389
385
  }) => {
390
386
  var _req$headers, _req$headers$authoriz;
391
387
 
392
- const session = await get({
393
- req,
394
- createContext
395
- });
396
- const sudoContext = createContext({
397
- sudo: true
398
- });
399
388
  const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
400
389
  let nextSession;
401
390
 
@@ -403,6 +392,10 @@ function createAuth({
403
392
  return;
404
393
  }
405
394
 
395
+ const sudoContext = createContext({
396
+ sudo: true
397
+ });
398
+
406
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') {
407
400
  nextSession = await jwt.getToken({
408
401
  req,
@@ -418,11 +411,21 @@ function createAuth({
418
411
  return;
419
412
  }
420
413
 
421
- return _objectSpread(_objectSpread({}, nextSession), {}, {
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), {}, {
422
425
  data: nextSession.data,
423
426
  listKey: nextSession.listKey,
424
427
  itemId: nextSession.itemId
425
- }, session);
428
+ });
426
429
  },
427
430
  end: async ({
428
431
  res,
@@ -135,13 +135,9 @@ import keystoneConfig from '../../../../../keystone';
135
135
  import { PrismaClient } from '.prisma/client';
136
136
  import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
137
137
 
138
- const prisma = global.prisma || PrismaClient
138
+ const keystoneQueryAPI = global.keystoneQueryAPI || createQueryAPI(keystoneConfig, PrismaClient);
139
139
 
140
- if (process.env.NODE_ENV !== 'production') global.prisma = prisma
141
-
142
- const query = global.query || createQueryAPI(keystoneConfig, prisma);
143
-
144
- if (process.env.NODE_ENV !== 'production') global.query = query
140
+ if (process.env.NODE_ENV !== 'production') globalThis.keystoneQueryAPI = keystoneQueryAPI
145
141
 
146
142
  export default getNextAuthPage({
147
143
  autoCreate: <%= autoCreate %>,
@@ -149,7 +145,7 @@ export default getNextAuthPage({
149
145
  listKey: '<%= listKey %>',
150
146
  pages: keystoneConfig.pages,
151
147
  providers: keystoneConfig.providers,
152
- query,
148
+ query: keystoneQueryAPI,
153
149
  resolver: keystoneConfig.resolver,
154
150
  sessionData: '<%= sessionData %>',
155
151
  sessionSecret: '<%= sessionSecret %>',
@@ -357,13 +353,6 @@ function createAuth({
357
353
  }) => {
358
354
  var _req$headers, _req$headers$authoriz;
359
355
 
360
- const session = await get({
361
- req,
362
- createContext
363
- });
364
- const sudoContext = createContext({
365
- sudo: true
366
- });
367
356
  const pathname = url.parse(req === null || req === void 0 ? void 0 : req.url).pathname;
368
357
  let nextSession;
369
358
 
@@ -371,6 +360,10 @@ function createAuth({
371
360
  return;
372
361
  }
373
362
 
363
+ const sudoContext = createContext({
364
+ sudo: true
365
+ });
366
+
374
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') {
375
368
  nextSession = await getToken({
376
369
  req,
@@ -386,11 +379,21 @@ function createAuth({
386
379
  return;
387
380
  }
388
381
 
389
- return _objectSpread(_objectSpread({}, nextSession), {}, {
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), {}, {
390
393
  data: nextSession.data,
391
394
  listKey: nextSession.listKey,
392
395
  itemId: nextSession.itemId
393
- }, session);
396
+ });
394
397
  },
395
398
  end: async ({
396
399
  res,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opensaas/keystone-nextjs-auth",
3
- "version": "22.2.0",
3
+ "version": "22.2.3",
4
4
  "repository": "https://github.com/opensaasau/keystone-nextjs-auth",
5
5
  "license": "MIT",
6
6
  "main": "dist/opensaas-keystone-nextjs-auth.cjs.js",
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 }) => {
@@ -7,13 +7,9 @@ import keystoneConfig from '../../../../../keystone';
7
7
  import { PrismaClient } from '.prisma/client';
8
8
  import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
9
9
 
10
- const prisma = global.prisma || PrismaClient
10
+ const keystoneQueryAPI = global.keystoneQueryAPI || createQueryAPI(keystoneConfig, PrismaClient);
11
11
 
12
- if (process.env.NODE_ENV !== 'production') global.prisma = prisma
13
-
14
- const query = global.query || createQueryAPI(keystoneConfig, prisma);
15
-
16
- if (process.env.NODE_ENV !== 'production') global.query = query
12
+ if (process.env.NODE_ENV !== 'production') globalThis.keystoneQueryAPI = keystoneQueryAPI
17
13
 
18
14
  export default getNextAuthPage({
19
15
  autoCreate: <%= autoCreate %>,
@@ -21,7 +17,7 @@ export default getNextAuthPage({
21
17
  listKey: '<%= listKey %>',
22
18
  pages: keystoneConfig.pages,
23
19
  providers: keystoneConfig.providers,
24
- query,
20
+ query: keystoneQueryAPI,
25
21
  resolver: keystoneConfig.resolver,
26
22
  sessionData: '<%= sessionData %>',
27
23
  sessionSecret: '<%= sessionSecret %>',