@opensaas/keystone-nextjs-auth 22.1.0 → 22.2.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,15 @@
1
1
  # @opensaas-keystone/nextjs-auth
2
2
 
3
+ ## 22.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4a2f20a: Allow custom session `get`, `start` and `end`
8
+
9
+ ### Patch Changes
10
+
11
+ - 4a2f20a: Set prisma and query on global in dev to prevent instantiating extra `PrismaClient` instances
12
+
3
13
  ## 22.1.0
4
14
 
5
15
  ### Minor Changes
@@ -2,30 +2,29 @@ import { CookiesOptions, EventCallbacks, PagesOptions } from 'next-auth';
2
2
  import type { KeystoneListsAPI } from '@keystone-6/core/types';
3
3
  import { Provider } from 'next-auth/providers';
4
4
  import { JWTOptions } from 'next-auth/jwt';
5
- declare type CoreNextAuthPageProps = {
5
+ export declare type NextAuthTemplateProps = {
6
6
  autoCreate: boolean;
7
+ identityField: string;
8
+ listKey: string;
9
+ sessionData: string | undefined;
10
+ sessionSecret: string;
11
+ };
12
+ export declare type CoreNextAuthPageProps = {
7
13
  cookies?: Partial<CookiesOptions>;
8
14
  events?: Partial<EventCallbacks>;
9
- identityField: string;
10
15
  jwt?: Partial<JWTOptions>;
11
- listKey: string;
12
16
  pages?: Partial<PagesOptions>;
13
- providers?: Provider[];
17
+ providers: Provider[];
14
18
  resolver?: (args: {
15
19
  user: any;
16
20
  profile: any;
17
21
  account: any;
18
- }) => {
22
+ }) => Promise<{
19
23
  [key: string]: boolean | string | number;
20
- };
21
- sessionData: string | undefined;
22
- sessionSecret: string;
23
- };
24
- declare type NextAuthGglProps = {
25
- mutationName?: string;
26
- query?: KeystoneListsAPI<any>;
24
+ }>;
25
+ } & NextAuthTemplateProps;
26
+ export declare type NextAuthPageProps = CoreNextAuthPageProps & {
27
+ query: KeystoneListsAPI<any>;
27
28
  };
28
- export declare type NextAuthPageProps = CoreNextAuthPageProps & NextAuthGglProps;
29
29
  export default function NextAuthPage(props: NextAuthPageProps): any;
30
30
  export declare const getNextAuthPage: (props: NextAuthPageProps) => () => any;
31
- export {};
@@ -1,4 +1,2 @@
1
- import { NextAuthPageProps } from '../pages/NextAuthPage';
2
- declare type AuthTemplateOptions = NextAuthPageProps;
3
- export declare const authTemplate: ({ autoCreate, identityField, listKey, sessionData, sessionSecret, }: AuthTemplateOptions) => string;
4
- export {};
1
+ import { NextAuthTemplateProps } from '../pages/NextAuthPage';
2
+ export declare const authTemplate: ({ autoCreate, identityField, listKey, sessionData, sessionSecret, }: NextAuthTemplateProps) => string;
@@ -164,8 +164,17 @@ const getSchemaExtension = ({
164
164
 
165
165
  const template = `
166
166
  import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
167
- import { query } from '.keystone/api';
168
167
  import keystoneConfig from '../../../../../keystone';
168
+ import { PrismaClient } from '.prisma/client';
169
+ import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
170
+
171
+ const prisma = global.prisma || PrismaClient
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
169
178
 
170
179
  export default getNextAuthPage({
171
180
  autoCreate: <%= autoCreate %>,
@@ -196,7 +205,7 @@ const authTemplate = ({
196
205
  return authOut;
197
206
  };
198
207
 
199
- const _excluded = ["get"];
208
+ const _excluded = ["get", "end"];
200
209
  /**
201
210
  * createAuth function
202
211
  *
@@ -368,18 +377,23 @@ function createAuth({
368
377
 
369
378
 
370
379
  const withItemData = _sessionStrategy => {
371
- const sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
380
+ const {
381
+ get,
382
+ end
383
+ } = _sessionStrategy,
384
+ sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
372
385
 
373
386
  return _objectSpread(_objectSpread({}, sessionStrategy), {}, {
374
- start: async () => {
375
- return 'false';
376
- },
377
387
  get: async ({
378
388
  req,
379
389
  createContext
380
390
  }) => {
381
391
  var _req$headers, _req$headers$authoriz;
382
392
 
393
+ const session = await get({
394
+ req,
395
+ createContext
396
+ });
383
397
  const sudoContext = createContext({
384
398
  sudo: true
385
399
  });
@@ -409,12 +423,18 @@ function createAuth({
409
423
  data: nextSession.data,
410
424
  listKey: nextSession.listKey,
411
425
  itemId: nextSession.itemId
412
- });
426
+ }, session);
413
427
  },
414
428
  end: async ({
415
429
  res,
416
- req
430
+ req,
431
+ createContext
417
432
  }) => {
433
+ await end({
434
+ res,
435
+ req,
436
+ createContext
437
+ });
418
438
  const TOKEN_NAME = process.env.NODE_ENV === 'production' ? '__Secure-next-auth.session-token' : 'next-auth.session-token';
419
439
  res.setHeader('Set-Cookie', cookie__namespace.serialize(TOKEN_NAME, '', {
420
440
  maxAge: 0,
@@ -163,8 +163,17 @@ const getSchemaExtension = ({
163
163
 
164
164
  const template = `
165
165
  import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
166
- import { query } from '.keystone/api';
167
166
  import keystoneConfig from '../../../../../keystone';
167
+ import { PrismaClient } from '.prisma/client';
168
+ import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
169
+
170
+ const prisma = global.prisma || PrismaClient
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
168
177
 
169
178
  export default getNextAuthPage({
170
179
  autoCreate: <%= autoCreate %>,
@@ -195,7 +204,7 @@ const authTemplate = ({
195
204
  return authOut;
196
205
  };
197
206
 
198
- const _excluded = ["get"];
207
+ const _excluded = ["get", "end"];
199
208
  /**
200
209
  * createAuth function
201
210
  *
@@ -367,18 +376,23 @@ function createAuth({
367
376
 
368
377
 
369
378
  const withItemData = _sessionStrategy => {
370
- const sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
379
+ const {
380
+ get,
381
+ end
382
+ } = _sessionStrategy,
383
+ sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
371
384
 
372
385
  return _objectSpread(_objectSpread({}, sessionStrategy), {}, {
373
- start: async () => {
374
- return 'false';
375
- },
376
386
  get: async ({
377
387
  req,
378
388
  createContext
379
389
  }) => {
380
390
  var _req$headers, _req$headers$authoriz;
381
391
 
392
+ const session = await get({
393
+ req,
394
+ createContext
395
+ });
382
396
  const sudoContext = createContext({
383
397
  sudo: true
384
398
  });
@@ -408,12 +422,18 @@ function createAuth({
408
422
  data: nextSession.data,
409
423
  listKey: nextSession.listKey,
410
424
  itemId: nextSession.itemId
411
- });
425
+ }, session);
412
426
  },
413
427
  end: async ({
414
428
  res,
415
- req
429
+ req,
430
+ createContext
416
431
  }) => {
432
+ await end({
433
+ res,
434
+ req,
435
+ createContext
436
+ });
417
437
  const TOKEN_NAME = '__Secure-next-auth.session-token' ;
418
438
  res.setHeader('Set-Cookie', cookie__namespace.serialize(TOKEN_NAME, '', {
419
439
  maxAge: 0,
@@ -131,8 +131,17 @@ const getSchemaExtension = ({
131
131
 
132
132
  const template = `
133
133
  import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
134
- import { query } from '.keystone/api';
135
134
  import keystoneConfig from '../../../../../keystone';
135
+ import { PrismaClient } from '.prisma/client';
136
+ import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
137
+
138
+ const prisma = global.prisma || PrismaClient
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
136
145
 
137
146
  export default getNextAuthPage({
138
147
  autoCreate: <%= autoCreate %>,
@@ -163,7 +172,7 @@ const authTemplate = ({
163
172
  return authOut;
164
173
  };
165
174
 
166
- const _excluded = ["get"];
175
+ const _excluded = ["get", "end"];
167
176
  /**
168
177
  * createAuth function
169
178
  *
@@ -335,18 +344,23 @@ function createAuth({
335
344
 
336
345
 
337
346
  const withItemData = _sessionStrategy => {
338
- const sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
347
+ const {
348
+ get,
349
+ end
350
+ } = _sessionStrategy,
351
+ sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
339
352
 
340
353
  return _objectSpread(_objectSpread({}, sessionStrategy), {}, {
341
- start: async () => {
342
- return 'false';
343
- },
344
354
  get: async ({
345
355
  req,
346
356
  createContext
347
357
  }) => {
348
358
  var _req$headers, _req$headers$authoriz;
349
359
 
360
+ const session = await get({
361
+ req,
362
+ createContext
363
+ });
350
364
  const sudoContext = createContext({
351
365
  sudo: true
352
366
  });
@@ -376,12 +390,18 @@ function createAuth({
376
390
  data: nextSession.data,
377
391
  listKey: nextSession.listKey,
378
392
  itemId: nextSession.itemId
379
- });
393
+ }, session);
380
394
  },
381
395
  end: async ({
382
396
  res,
383
- req
397
+ req,
398
+ createContext
384
399
  }) => {
400
+ await end({
401
+ res,
402
+ req,
403
+ createContext
404
+ });
385
405
  const TOKEN_NAME = process.env.NODE_ENV === 'production' ? '__Secure-next-auth.session-token' : 'next-auth.session-token';
386
406
  res.setHeader('Set-Cookie', cookie.serialize(TOKEN_NAME, '', {
387
407
  maxAge: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opensaas/keystone-nextjs-auth",
3
- "version": "22.1.0",
3
+ "version": "22.2.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",
@@ -81,7 +81,6 @@ function NextAuthPage(props) {
81
81
  }
82
82
 
83
83
  const list = query[listKey];
84
- const queryAPI = query[listKey];
85
84
  const protectIdentities = true;
86
85
  return NextAuth__default["default"]({
87
86
  cookies,
@@ -111,7 +110,7 @@ function NextAuthPage(props) {
111
110
  account,
112
111
  profile
113
112
  }) : {};
114
- const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI); // ID
113
+ const result = await validateNextAuth(identityField, identity, protectIdentities, list); // ID
115
114
 
116
115
  const data = _objectSpread({
117
116
  [identityField]: identity
@@ -119,11 +118,9 @@ function NextAuthPage(props) {
119
118
 
120
119
  if (!result.success) {
121
120
  if (!autoCreate) {
122
- console.log('`autoCreate` is set to `false`, skipping user auto-creation');
123
121
  return false;
124
122
  }
125
123
 
126
- console.log('`autoCreate` is set to `true`, auto-creating a new user');
127
124
  const createUser = await list.createOne({
128
125
  data
129
126
  }).then(returned => {
@@ -132,14 +129,12 @@ function NextAuthPage(props) {
132
129
  user: returned
133
130
  };
134
131
  }).catch(error => {
135
- console.log(error);
132
+ console.error(error);
136
133
  throw new Error(error);
137
134
  });
138
- console.log('Created User', createUser);
139
135
  return createUser.success;
140
136
  }
141
137
 
142
- console.log('Data', data);
143
138
  const updateUser = await list.updateOne({
144
139
  where: {
145
140
  id: result.item.id
@@ -151,7 +146,7 @@ function NextAuthPage(props) {
151
146
  user: returned
152
147
  };
153
148
  }).catch(error => {
154
- console.log(error);
149
+ console.error(error);
155
150
  throw new Error(error);
156
151
  });
157
152
  return updateUser.success;
@@ -182,7 +177,6 @@ function NextAuthPage(props) {
182
177
  });
183
178
  }
184
179
 
185
- console.log('Session', returnSession);
186
180
  return returnSession;
187
181
  },
188
182
 
@@ -190,7 +184,7 @@ function NextAuthPage(props) {
190
184
  token
191
185
  }) {
192
186
  const identity = token.sub;
193
- const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
187
+ const result = await validateNextAuth(identityField, identity, protectIdentities, list);
194
188
 
195
189
  if (!result.success) {
196
190
  token.itemId = null;
@@ -81,7 +81,6 @@ function NextAuthPage(props) {
81
81
  }
82
82
 
83
83
  const list = query[listKey];
84
- const queryAPI = query[listKey];
85
84
  const protectIdentities = true;
86
85
  return NextAuth__default["default"]({
87
86
  cookies,
@@ -111,7 +110,7 @@ function NextAuthPage(props) {
111
110
  account,
112
111
  profile
113
112
  }) : {};
114
- const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI); // ID
113
+ const result = await validateNextAuth(identityField, identity, protectIdentities, list); // ID
115
114
 
116
115
  const data = _objectSpread({
117
116
  [identityField]: identity
@@ -119,11 +118,9 @@ function NextAuthPage(props) {
119
118
 
120
119
  if (!result.success) {
121
120
  if (!autoCreate) {
122
- console.log('`autoCreate` is set to `false`, skipping user auto-creation');
123
121
  return false;
124
122
  }
125
123
 
126
- console.log('`autoCreate` is set to `true`, auto-creating a new user');
127
124
  const createUser = await list.createOne({
128
125
  data
129
126
  }).then(returned => {
@@ -132,14 +129,12 @@ function NextAuthPage(props) {
132
129
  user: returned
133
130
  };
134
131
  }).catch(error => {
135
- console.log(error);
132
+ console.error(error);
136
133
  throw new Error(error);
137
134
  });
138
- console.log('Created User', createUser);
139
135
  return createUser.success;
140
136
  }
141
137
 
142
- console.log('Data', data);
143
138
  const updateUser = await list.updateOne({
144
139
  where: {
145
140
  id: result.item.id
@@ -151,7 +146,7 @@ function NextAuthPage(props) {
151
146
  user: returned
152
147
  };
153
148
  }).catch(error => {
154
- console.log(error);
149
+ console.error(error);
155
150
  throw new Error(error);
156
151
  });
157
152
  return updateUser.success;
@@ -182,7 +177,6 @@ function NextAuthPage(props) {
182
177
  });
183
178
  }
184
179
 
185
- console.log('Session', returnSession);
186
180
  return returnSession;
187
181
  },
188
182
 
@@ -190,7 +184,7 @@ function NextAuthPage(props) {
190
184
  token
191
185
  }) {
192
186
  const identity = token.sub;
193
- const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
187
+ const result = await validateNextAuth(identityField, identity, protectIdentities, list);
194
188
 
195
189
  if (!result.success) {
196
190
  token.itemId = null;
@@ -73,7 +73,6 @@ function NextAuthPage(props) {
73
73
  }
74
74
 
75
75
  const list = query[listKey];
76
- const queryAPI = query[listKey];
77
76
  const protectIdentities = true;
78
77
  return NextAuth({
79
78
  cookies,
@@ -103,7 +102,7 @@ function NextAuthPage(props) {
103
102
  account,
104
103
  profile
105
104
  }) : {};
106
- const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI); // ID
105
+ const result = await validateNextAuth(identityField, identity, protectIdentities, list); // ID
107
106
 
108
107
  const data = _objectSpread({
109
108
  [identityField]: identity
@@ -111,11 +110,9 @@ function NextAuthPage(props) {
111
110
 
112
111
  if (!result.success) {
113
112
  if (!autoCreate) {
114
- console.log('`autoCreate` is set to `false`, skipping user auto-creation');
115
113
  return false;
116
114
  }
117
115
 
118
- console.log('`autoCreate` is set to `true`, auto-creating a new user');
119
116
  const createUser = await list.createOne({
120
117
  data
121
118
  }).then(returned => {
@@ -124,14 +121,12 @@ function NextAuthPage(props) {
124
121
  user: returned
125
122
  };
126
123
  }).catch(error => {
127
- console.log(error);
124
+ console.error(error);
128
125
  throw new Error(error);
129
126
  });
130
- console.log('Created User', createUser);
131
127
  return createUser.success;
132
128
  }
133
129
 
134
- console.log('Data', data);
135
130
  const updateUser = await list.updateOne({
136
131
  where: {
137
132
  id: result.item.id
@@ -143,7 +138,7 @@ function NextAuthPage(props) {
143
138
  user: returned
144
139
  };
145
140
  }).catch(error => {
146
- console.log(error);
141
+ console.error(error);
147
142
  throw new Error(error);
148
143
  });
149
144
  return updateUser.success;
@@ -174,7 +169,6 @@ function NextAuthPage(props) {
174
169
  });
175
170
  }
176
171
 
177
- console.log('Session', returnSession);
178
172
  return returnSession;
179
173
  },
180
174
 
@@ -182,7 +176,7 @@ function NextAuthPage(props) {
182
176
  token
183
177
  }) {
184
178
  const identity = token.sub;
185
- const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
179
+ const result = await validateNextAuth(identityField, identity, protectIdentities, list);
186
180
 
187
181
  if (!result.success) {
188
182
  token.itemId = null;
package/src/index.ts CHANGED
@@ -194,13 +194,11 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
194
194
  const withItemData = (
195
195
  _sessionStrategy: AuthSessionStrategy<Record<string, any>>
196
196
  ): AuthSessionStrategy<{ listKey: string; itemId: string; data: any }> => {
197
- const { get, ...sessionStrategy } = _sessionStrategy;
197
+ const { get, end, ...sessionStrategy } = _sessionStrategy;
198
198
  return {
199
199
  ...sessionStrategy,
200
- start: async () => {
201
- return 'false';
202
- },
203
200
  get: async ({ req, createContext }) => {
201
+ const session = await get({ req, createContext });
204
202
  const sudoContext = createContext({ sudo: true });
205
203
  const pathname = url.parse(req?.url!).pathname!;
206
204
  let nextSession: Session;
@@ -231,9 +229,11 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
231
229
  data: nextSession.data,
232
230
  listKey: nextSession.listKey,
233
231
  itemId: nextSession.itemId,
232
+ ...session,
234
233
  };
235
234
  },
236
- end: async ({ res, req }) => {
235
+ end: async ({ res, req, createContext }) => {
236
+ await end({ res, req, createContext });
237
237
  const TOKEN_NAME =
238
238
  process.env.NODE_ENV === 'production'
239
239
  ? '__Secure-next-auth.session-token'
@@ -4,28 +4,28 @@ import { Provider } from 'next-auth/providers';
4
4
  import { JWTOptions } from 'next-auth/jwt';
5
5
  import { validateNextAuth } from '../lib/validateNextAuth';
6
6
 
7
- type CoreNextAuthPageProps = {
7
+ export type NextAuthTemplateProps = {
8
8
  autoCreate: boolean;
9
- cookies?: Partial<CookiesOptions>;
10
- events?: Partial<EventCallbacks>;
11
9
  identityField: string;
12
- jwt?: Partial<JWTOptions>;
13
10
  listKey: string;
14
- pages?: Partial<PagesOptions>;
15
- providers?: Provider[];
16
- resolver?: (args: { user: any; profile: any; account: any }) => {
17
- [key: string]: boolean | string | number;
18
- };
19
11
  sessionData: string | undefined;
20
12
  sessionSecret: string;
21
13
  };
22
14
 
23
- type NextAuthGglProps = {
24
- mutationName?: string;
25
- query?: KeystoneListsAPI<any>;
26
- };
15
+ export type CoreNextAuthPageProps = {
16
+ cookies?: Partial<CookiesOptions>;
17
+ events?: Partial<EventCallbacks>;
18
+ jwt?: Partial<JWTOptions>;
19
+ pages?: Partial<PagesOptions>;
20
+ providers: Provider[];
21
+ resolver?: (args: { user: any; profile: any; account: any }) => Promise<{
22
+ [key: string]: boolean | string | number;
23
+ }>;
24
+ } & NextAuthTemplateProps;
27
25
 
28
- export type NextAuthPageProps = CoreNextAuthPageProps & NextAuthGglProps;
26
+ export type NextAuthPageProps = CoreNextAuthPageProps & {
27
+ query: KeystoneListsAPI<any>;
28
+ };
29
29
 
30
30
  export default function NextAuthPage(props: NextAuthPageProps) {
31
31
  const {
@@ -54,7 +54,6 @@ export default function NextAuthPage(props: NextAuthPageProps) {
54
54
  }
55
55
 
56
56
  const list = query[listKey];
57
- const queryAPI = query[listKey];
58
57
  const protectIdentities = true;
59
58
 
60
59
  return NextAuth({
@@ -76,7 +75,7 @@ export default function NextAuthPage(props: NextAuthPageProps) {
76
75
  }
77
76
  const userInput = resolver ? await resolver({ user, account, profile }) : {};
78
77
 
79
- const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
78
+ const result = await validateNextAuth(identityField, identity, protectIdentities, list);
80
79
  // ID
81
80
  const data: any = {
82
81
  [identityField]: identity,
@@ -85,10 +84,8 @@ export default function NextAuthPage(props: NextAuthPageProps) {
85
84
 
86
85
  if (!result.success) {
87
86
  if (!autoCreate) {
88
- console.log('`autoCreate` is set to `false`, skipping user auto-creation');
89
87
  return false;
90
88
  }
91
- console.log('`autoCreate` is set to `true`, auto-creating a new user');
92
89
 
93
90
  const createUser = await list
94
91
  .createOne({ data })
@@ -96,13 +93,11 @@ export default function NextAuthPage(props: NextAuthPageProps) {
96
93
  return { success: true, user: returned };
97
94
  })
98
95
  .catch(error => {
99
- console.log(error);
96
+ console.error(error);
100
97
  throw new Error(error);
101
98
  });
102
- console.log('Created User', createUser);
103
99
  return createUser.success;
104
100
  }
105
- console.log('Data', data);
106
101
 
107
102
  const updateUser = await list
108
103
  .updateOne({ where: { id: result.item.id }, data })
@@ -110,7 +105,7 @@ export default function NextAuthPage(props: NextAuthPageProps) {
110
105
  return { success: true, user: returned };
111
106
  })
112
107
  .catch(error => {
113
- console.log(error);
108
+ console.error(error);
114
109
  throw new Error(error);
115
110
  });
116
111
  return updateUser.success;
@@ -131,13 +126,12 @@ export default function NextAuthPage(props: NextAuthPageProps) {
131
126
  itemId: token.itemId as string,
132
127
  };
133
128
  }
134
- console.log('Session', returnSession);
135
129
 
136
130
  return returnSession;
137
131
  },
138
132
  async jwt({ token }) {
139
133
  const identity = token.sub as number | string;
140
- const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
134
+ const result = await validateNextAuth(identityField, identity, protectIdentities, list);
141
135
 
142
136
  if (!result.success) {
143
137
  token.itemId = null;
@@ -1,10 +1,19 @@
1
1
  import ejs from 'ejs';
2
- import { NextAuthPageProps } from '../pages/NextAuthPage';
2
+ import { NextAuthTemplateProps } from '../pages/NextAuthPage';
3
3
 
4
4
  const template = `
5
5
  import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
6
- import { query } from '.keystone/api';
7
6
  import keystoneConfig from '../../../../../keystone';
7
+ import { PrismaClient } from '.prisma/client';
8
+ import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
9
+
10
+ const prisma = global.prisma || PrismaClient
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
8
17
 
9
18
  export default getNextAuthPage({
10
19
  autoCreate: <%= autoCreate %>,
@@ -19,15 +28,13 @@ export default getNextAuthPage({
19
28
  });
20
29
  `;
21
30
 
22
- type AuthTemplateOptions = NextAuthPageProps;
23
-
24
31
  export const authTemplate = ({
25
32
  autoCreate,
26
33
  identityField,
27
34
  listKey,
28
35
  sessionData,
29
36
  sessionSecret,
30
- }: AuthTemplateOptions) => {
37
+ }: NextAuthTemplateProps) => {
31
38
  const authOut = ejs.render(template, {
32
39
  identityField,
33
40
  sessionData,