@opensaas/keystone-nextjs-auth 20.3.0 → 21.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,17 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
2
2
  import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
3
3
  import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
4
+ import _indexOfInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/index-of';
5
+ import _Object$values from '@babel/runtime-corejs3/core-js-stable/object/values';
4
6
  import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
5
7
  import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
6
8
  import _URL from '@babel/runtime-corejs3/core-js-stable/url';
7
9
  import url from 'url';
8
10
  import { getSession } from 'next-auth/react';
11
+ import { getToken } from 'next-auth/jwt';
9
12
  import * as cookie from 'cookie';
10
13
  import ejs from 'ejs';
11
14
  import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
12
- import { assertInputObjectType, GraphQLString, GraphQLID } from 'graphql';
13
15
  import { graphql } from '@keystone-6/core';
14
16
 
15
17
  const template$1 = `
@@ -21,6 +23,9 @@ module.exports = withPreconstruct({
21
23
  typescript: {
22
24
  ignoreBuildErrors: true,
23
25
  },
26
+ env: {
27
+ NEXTAUTH_URL: process.env.NEXTAUTH_URL || 'http://localhost:<%= process.env.PORT || 3000 %><%= keystonePath || '' %>/api/auth',
28
+ },
24
29
  eslint: {
25
30
  ignoreDuringBuilds: true,
26
31
  },
@@ -76,7 +81,6 @@ const nextConfigTemplate = ({
76
81
 
77
82
  function getBaseAuthSchema({
78
83
  listKey,
79
- gqlNames,
80
84
  base
81
85
  }) {
82
86
  const extension = {
@@ -116,22 +120,12 @@ function getBaseAuthSchema({
116
120
  }
117
121
 
118
122
  const getSchemaExtension = ({
119
- identityField,
120
- listKey,
121
- gqlNames
123
+ listKey
122
124
  }) => graphql.extend(base => {
123
125
  var _context;
124
126
 
125
- const uniqueWhereInputType = assertInputObjectType(base.schema.getType(`${listKey}WhereUniqueInput`));
126
- const identityFieldOnUniqueWhere = uniqueWhereInputType.getFields()[identityField];
127
-
128
- if ((identityFieldOnUniqueWhere === null || identityFieldOnUniqueWhere === void 0 ? void 0 : identityFieldOnUniqueWhere.type) !== GraphQLString && (identityFieldOnUniqueWhere === null || identityFieldOnUniqueWhere === void 0 ? void 0 : identityFieldOnUniqueWhere.type) !== GraphQLID) {
129
- throw new Error(`createAuth was called with an identityField of ${identityField} on the list ${listKey} ` + `but that field doesn't allow being searched uniquely with a String or ID. ` + `You should likely add \`isIndexed: 'unique'\` ` + `to the field at ${listKey}.${identityField}`);
130
- }
131
-
132
127
  const baseSchema = getBaseAuthSchema({
133
128
  listKey,
134
- gqlNames,
135
129
  base
136
130
  });
137
131
  return _filterInstanceProperty(_context = [baseSchema.extension]).call(_context, x => x !== undefined);
@@ -143,44 +137,35 @@ import { query } from '.keystone/api';
143
137
  import keystoneConfig from '../../../../../keystone';
144
138
 
145
139
  export default getNextAuthPage({
140
+ autoCreate: <%= autoCreate %>,
146
141
  identityField: '<%= identityField %>',
147
- sessionData: '<%= sessionData %>',
148
142
  listKey: '<%= listKey %>',
149
- userMap: <%- JSON.stringify(userMap) %>,
150
- accountMap: <%- JSON.stringify(accountMap) %>,
151
- profileMap: <%- JSON.stringify(profileMap) %>,
152
- autoCreate: <%= autoCreate %>,
153
- sessionSecret: '<%= sessionSecret %>',
143
+ pages: keystoneConfig.pages,
154
144
  providers: keystoneConfig.providers,
155
145
  query,
146
+ resolver: keystoneConfig.resolver,
147
+ sessionData: '<%= sessionData %>',
148
+ sessionSecret: '<%= sessionSecret %>',
156
149
  });
157
150
  `;
158
151
  const authTemplate = ({
159
- gqlNames,
152
+ autoCreate,
160
153
  identityField,
161
- sessionData,
162
154
  listKey,
163
- autoCreate,
164
- userMap,
165
- accountMap,
166
- profileMap,
155
+ sessionData,
167
156
  sessionSecret
168
157
  }) => {
169
158
  const authOut = ejs.render(template, {
170
- gqlNames,
171
159
  identityField,
172
160
  sessionData,
173
161
  listKey,
174
162
  autoCreate,
175
- userMap,
176
- accountMap,
177
- profileMap,
178
163
  sessionSecret
179
164
  });
180
165
  return authOut;
181
166
  };
182
167
 
183
- const _excluded = ["get"];
168
+ const _excluded = ["get", "start"];
184
169
  /**
185
170
  * createAuth function
186
171
  *
@@ -188,31 +173,21 @@ const _excluded = ["get"];
188
173
  */
189
174
 
190
175
  function createAuth({
191
- listKey,
192
- identityField,
193
- sessionData,
194
176
  autoCreate,
195
- userMap,
196
- accountMap,
197
- profileMap,
177
+ cookies,
178
+ identityField,
179
+ listKey,
198
180
  keystonePath,
181
+ pages,
182
+ resolver,
199
183
  providers,
184
+ sessionData,
200
185
  sessionSecret
201
186
  }) {
202
187
  // The protectIdentities flag is currently under review to see whether it should be
203
188
  // part of the createAuth API (in which case its use cases need to be documented and tested)
204
189
  // or whether always being true is what we want, in which case we can refactor our code
205
190
  // to match this. -TL
206
- const gqlNames = {
207
- // Core
208
- authenticateItemWithPassword: `authenticate${listKey}WithPassword`,
209
- ItemAuthenticationWithPasswordResult: `${listKey}AuthenticationWithPasswordResult`,
210
- ItemAuthenticationWithPasswordSuccess: `${listKey}AuthenticationWithPasswordSuccess`,
211
- ItemAuthenticationWithPasswordFailure: `${listKey}AuthenticationWithPasswordFailure`,
212
- // Initial data
213
- CreateInitialInput: `CreateInitial${listKey}Input`,
214
- createInitialItem: `createInitial${listKey}`
215
- };
216
191
  const customPath = !keystonePath || keystonePath === '/' ? '' : keystonePath;
217
192
  /**
218
193
  * pageMiddleware
@@ -229,16 +204,14 @@ function createAuth({
229
204
  context,
230
205
  isValidSession
231
206
  }) => {
207
+ var _context;
208
+
232
209
  const {
233
210
  req,
234
211
  session
235
212
  } = context;
236
213
  const pathname = url.parse(req === null || req === void 0 ? void 0 : req.url).pathname;
237
214
 
238
- if (pathname === `${customPath}/api/__keystone_api_build`) {
239
- return;
240
- }
241
-
242
215
  if (isValidSession) {
243
216
  if (pathname === `${customPath}/api/auth/signin`) {
244
217
  return {
@@ -257,7 +230,11 @@ function createAuth({
257
230
  return;
258
231
  }
259
232
 
260
- if (!session && !_includesInstanceProperty(pathname).call(pathname, `${customPath}/api/auth/`)) {
233
+ if (_includesInstanceProperty(pathname).call(pathname, '/_next/') || _includesInstanceProperty(pathname).call(pathname, '/api/auth/')) {
234
+ return;
235
+ }
236
+
237
+ if (!session && !_includesInstanceProperty(pathname).call(pathname, `${customPath}/api/auth/`) && !(_indexOfInstanceProperty(_context = _Object$values(pages)).call(_context, pathname) > -1)) {
261
238
  return {
262
239
  kind: 'redirect',
263
240
  to: `${customPath}/api/auth/signin`
@@ -279,14 +256,10 @@ function createAuth({
279
256
  mode: 'write',
280
257
  outputPath: 'pages/api/auth/[...nextauth].js',
281
258
  src: authTemplate({
282
- gqlNames,
259
+ autoCreate,
283
260
  identityField,
284
- sessionData,
285
261
  listKey,
286
- autoCreate,
287
- userMap,
288
- accountMap,
289
- profileMap,
262
+ sessionData,
290
263
  sessionSecret
291
264
  })
292
265
  }, {
@@ -305,7 +278,8 @@ function createAuth({
305
278
  */
306
279
 
307
280
 
308
- const publicPages = [`${customPath}/api/auth/csrf`, `${customPath}/api/auth/signin`, `${customPath}/api/auth/callback`, `${customPath}/api/auth/session`, `${customPath}/api/auth/providers`, `${customPath}/api/auth/signout`];
281
+ const publicPages = [`${customPath}/api/__keystone_api_build`, `${customPath}/api/auth/csrf`, `${customPath}/api/auth/signin`, `${customPath}/api/auth/callback`, `${customPath}/api/auth/session`, `${customPath}/api/auth/providers`, `${customPath}/api/auth/signout`, `${customPath}/api/auth/error`]; // TODO: Add Provider Types
282
+ // @ts-ignore
309
283
 
310
284
  function addPages(provider) {
311
285
  const name = provider.id;
@@ -323,8 +297,7 @@ function createAuth({
323
297
 
324
298
  const extendGraphqlSchema = getSchemaExtension({
325
299
  identityField,
326
- listKey,
327
- gqlNames
300
+ listKey
328
301
  });
329
302
  /**
330
303
  * validateConfig
@@ -338,7 +311,9 @@ function createAuth({
338
311
  if (listConfig === undefined) {
339
312
  const msg = `A createAuth() invocation specifies the list "${listKey}" but no list with that key has been defined.`;
340
313
  throw new Error(msg);
341
- } // TODO: Check for String-like typing for identityField? How?
314
+ } // TODO: Check if providers
315
+ // TODO: Check other required commands/data
316
+ // TODO: Check for String-like typing for identityField? How?
342
317
  // TODO: Validate that the identifyField is unique.
343
318
  // TODO: If this field isn't required, what happens if I try to log in as `null`?
344
319
 
@@ -346,9 +321,9 @@ function createAuth({
346
321
  const identityFieldConfig = listConfig.fields[identityField];
347
322
 
348
323
  if (identityFieldConfig === undefined) {
349
- const i = _JSON$stringify(identityField);
324
+ const identityFieldName = _JSON$stringify(identityField);
350
325
 
351
- const msg = `A createAuth() invocation for the "${listKey}" list specifies ${i} as its identityField but no field with that key exists on the list.`;
326
+ const msg = `A createAuth() invocation for the "${listKey}" list specifies ${identityFieldName} as its identityField but no field with that key exists on the list.`;
352
327
  throw new Error(msg);
353
328
  }
354
329
  };
@@ -364,18 +339,46 @@ function createAuth({
364
339
 
365
340
 
366
341
  const withItemData = _sessionStrategy => {
367
- const sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
342
+ const {
343
+ get,
344
+ start
345
+ } = _sessionStrategy,
346
+ sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
368
347
 
369
348
  return _objectSpread(_objectSpread({}, sessionStrategy), {}, {
349
+ start: async ({
350
+ res
351
+ }) => {
352
+ console.log('start');
353
+ const session = await start({
354
+ res
355
+ });
356
+ return session;
357
+ },
370
358
  get: async ({
371
359
  req
372
360
  }) => {
361
+ var _req$headers$authoriz;
362
+
373
363
  const pathname = url.parse(req === null || req === void 0 ? void 0 : req.url).pathname;
374
364
 
375
365
  if (_includesInstanceProperty(pathname).call(pathname, '/api/auth')) {
376
366
  return;
377
367
  }
378
368
 
369
+ if (((_req$headers$authoriz = req.headers.authorization) === null || _req$headers$authoriz === void 0 ? void 0 : _req$headers$authoriz.split(' ')[0]) === 'Bearer') {
370
+ var _token$data;
371
+
372
+ const token = await getToken({
373
+ req,
374
+ secret: sessionSecret
375
+ });
376
+
377
+ if (token !== null && token !== void 0 && (_token$data = token.data) !== null && _token$data !== void 0 && _token$data.id) {
378
+ return token;
379
+ }
380
+ }
381
+
379
382
  const nextSession = await getSession({
380
383
  req
381
384
  });
@@ -396,6 +399,7 @@ function createAuth({
396
399
  secure: process.env.NODE_ENV === 'production',
397
400
  path: '/',
398
401
  sameSite: 'lax',
402
+ // TODO: Update parse to URL
399
403
  domain: url.parse(req.url).hostname
400
404
  }));
401
405
  }
@@ -432,19 +436,23 @@ function createAuth({
432
436
  },
433
437
  enableSessionItem: true,
434
438
  isAccessAllowed: async context => {
435
- var _context$req, _context$req2, _keystoneConfig$ui3;
439
+ var _context$req, _keystoneConfig$ui3;
436
440
 
437
- if (process.env.NODE_ENV !== 'production' && ((_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.url) !== undefined && new _URL(context.req.url, 'http://example.com').pathname === `${customPath}/api/__keystone_api_build`) {
441
+ const {
442
+ req
443
+ } = context;
444
+ const pathname = url.parse(req === null || req === void 0 ? void 0 : req.url).pathname; // Allow nextjs scripts and static files to be accessed without auth
445
+
446
+ if (_includesInstanceProperty(pathname).call(pathname, '/_next/')) {
438
447
  return true;
439
- } // Allow access to the adminMeta data from the /init path to correctly render that page
440
- // even if the user isn't logged in (which should always be the case if they're seeing /init)
448
+ } // Allow keystone to access /api/__keystone_api_build for hot reloading
441
449
 
442
450
 
443
- const headers = (_context$req2 = context.req) === null || _context$req2 === void 0 ? void 0 : _context$req2.headers;
444
- const host = headers ? headers['x-forwarded-host'] || headers.host : null;
445
- const thisUrl = headers !== null && headers !== void 0 && headers.referer ? new _URL(headers.referer) : undefined;
446
- const accessingInitPage = (thisUrl === null || thisUrl === void 0 ? void 0 : thisUrl.pathname) === '/init' && (thisUrl === null || thisUrl === void 0 ? void 0 : thisUrl.host) === host && (await context.sudo().query[listKey].count({})) === 0;
447
- return accessingInitPage || ((_keystoneConfig$ui3 = keystoneConfig.ui) !== null && _keystoneConfig$ui3 !== void 0 && _keystoneConfig$ui3.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined);
451
+ if (process.env.NODE_ENV !== 'production' && ((_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.url) !== undefined && new _URL(context.req.url, 'http://example.com').pathname === `${customPath}/api/__keystone_api_build`) {
452
+ return true;
453
+ }
454
+
455
+ return (_keystoneConfig$ui3 = keystoneConfig.ui) !== null && _keystoneConfig$ui3 !== void 0 && _keystoneConfig$ui3.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined;
448
456
  }
449
457
  });
450
458
  }
@@ -454,8 +462,11 @@ function createAuth({
454
462
  const existingExtendGraphQLSchema = keystoneConfig.extendGraphqlSchema;
455
463
  return _objectSpread(_objectSpread({}, keystoneConfig), {}, {
456
464
  ui,
457
- session,
465
+ cookies,
458
466
  providers,
467
+ pages,
468
+ resolver,
469
+ session,
459
470
  lists: _objectSpread({}, keystoneConfig.lists),
460
471
  experimental: _objectSpread(_objectSpread({}, keystoneConfig.experimental), {}, {
461
472
  generateNodeAPI: true
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
2
2
  "name": "@opensaas/keystone-nextjs-auth",
3
- "version": "20.3.0",
3
+ "version": "21.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",
7
7
  "module": "dist/opensaas-keystone-nextjs-auth.esm.js",
8
8
  "dependencies": {
9
- "@babel/runtime": "^7.16.7",
10
- "@babel/runtime-corejs3": "^7.16.8",
9
+ "@babel/runtime": "^7.17.8",
10
+ "@babel/runtime-corejs3": "^7.17.8",
11
11
  "@types/ejs": "^3.1.0",
12
- "cookie": "^0.4.1",
12
+ "cookie": "^0.4.2",
13
13
  "cross-fetch": "^3.1.5",
14
14
  "ejs": "^3.1.6",
15
15
  "fast-deep-equal": "^3.1.3",
16
16
  "graphql": "^15.8.0",
17
- "next-auth": "^4.1.2"
17
+ "next-auth": "^4.3.1"
18
18
  },
19
19
  "devDependencies": {
20
- "@keystone-6/core": "^1.0.1",
20
+ "@keystone-6/core": "^1.1.0",
21
21
  "react": "^17.0.2"
22
22
  },
23
23
  "peerDependencies": {
24
- "@keystone-6/core": "^1.0.1",
24
+ "@keystone-6/core": "^1.1.0",
25
25
  "react": "^17.0.2"
26
26
  },
27
27
  "engines": {
@@ -58,23 +58,42 @@ async function validateNextAuth(identityField, identity, protectIdentities, item
58
58
 
59
59
  function NextAuthPage(props) {
60
60
  const {
61
+ autoCreate,
62
+ cookies,
63
+ events,
64
+ identityField,
65
+ jwt,
66
+ listKey,
67
+ pages,
61
68
  providers,
62
69
  query,
63
- identityField,
70
+ resolver,
64
71
  sessionData,
65
- listKey,
66
- autoCreate,
67
- userMap,
68
- accountMap,
69
- profileMap,
70
72
  sessionSecret
71
- } = props;
73
+ } = props; // TODO: (v1.1). https://github.com/ijsto/keystone-6-oauth/projects/1#card-78602004
74
+
75
+ console.log('NextAuthPages... ', pages);
76
+
77
+ if (!query) {
78
+ console.error('NextAuthPage got no query.');
79
+ return null;
80
+ }
81
+
82
+ if (!providers || !providers.length) {
83
+ console.error('You need to provide at least one provider.');
84
+ return null;
85
+ }
86
+
72
87
  const list = query[listKey];
73
88
  const queryAPI = query[listKey];
74
89
  const protectIdentities = true;
75
90
  return NextAuth__default["default"]({
76
- secret: sessionSecret,
91
+ cookies,
77
92
  providers,
93
+ pages: pages || {},
94
+ events: events || {},
95
+ jwt: jwt || {},
96
+ secret: sessionSecret,
78
97
  callbacks: {
79
98
  async signIn({
80
99
  user,
@@ -91,28 +110,16 @@ function NextAuthPage(props) {
91
110
  identity = 0;
92
111
  }
93
112
 
94
- const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
95
- const data = {}; // eslint-disable-next-line no-restricted-syntax
96
-
97
- for (const key in userMap) {
98
- if (Object.prototype.hasOwnProperty.call(userMap, key)) {
99
- data[key] = user[userMap[key]];
100
- }
101
- } // eslint-disable-next-line no-restricted-syntax
102
-
113
+ const userInput = resolver ? await resolver({
114
+ user,
115
+ account,
116
+ profile
117
+ }) : {};
118
+ const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI); // ID
103
119
 
104
- for (const key in accountMap) {
105
- if (Object.prototype.hasOwnProperty.call(accountMap, key)) {
106
- data[key] = account[accountMap[key]];
107
- }
108
- } // eslint-disable-next-line no-restricted-syntax
109
-
110
-
111
- for (const key in profileMap) {
112
- if (Object.prototype.hasOwnProperty.call(profileMap, key)) {
113
- data[key] = profile[profileMap[key]];
114
- }
115
- }
120
+ const data = _objectSpread({
121
+ [identityField]: identity
122
+ }, userInput);
116
123
 
117
124
  if (!result.success) {
118
125
  if (!autoCreate) {
@@ -58,23 +58,42 @@ async function validateNextAuth(identityField, identity, protectIdentities, item
58
58
 
59
59
  function NextAuthPage(props) {
60
60
  const {
61
+ autoCreate,
62
+ cookies,
63
+ events,
64
+ identityField,
65
+ jwt,
66
+ listKey,
67
+ pages,
61
68
  providers,
62
69
  query,
63
- identityField,
70
+ resolver,
64
71
  sessionData,
65
- listKey,
66
- autoCreate,
67
- userMap,
68
- accountMap,
69
- profileMap,
70
72
  sessionSecret
71
- } = props;
73
+ } = props; // TODO: (v1.1). https://github.com/ijsto/keystone-6-oauth/projects/1#card-78602004
74
+
75
+ console.log('NextAuthPages... ', pages);
76
+
77
+ if (!query) {
78
+ console.error('NextAuthPage got no query.');
79
+ return null;
80
+ }
81
+
82
+ if (!providers || !providers.length) {
83
+ console.error('You need to provide at least one provider.');
84
+ return null;
85
+ }
86
+
72
87
  const list = query[listKey];
73
88
  const queryAPI = query[listKey];
74
89
  const protectIdentities = true;
75
90
  return NextAuth__default["default"]({
76
- secret: sessionSecret,
91
+ cookies,
77
92
  providers,
93
+ pages: pages || {},
94
+ events: events || {},
95
+ jwt: jwt || {},
96
+ secret: sessionSecret,
78
97
  callbacks: {
79
98
  async signIn({
80
99
  user,
@@ -91,28 +110,16 @@ function NextAuthPage(props) {
91
110
  identity = 0;
92
111
  }
93
112
 
94
- const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
95
- const data = {}; // eslint-disable-next-line no-restricted-syntax
96
-
97
- for (const key in userMap) {
98
- if (Object.prototype.hasOwnProperty.call(userMap, key)) {
99
- data[key] = user[userMap[key]];
100
- }
101
- } // eslint-disable-next-line no-restricted-syntax
102
-
113
+ const userInput = resolver ? await resolver({
114
+ user,
115
+ account,
116
+ profile
117
+ }) : {};
118
+ const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI); // ID
103
119
 
104
- for (const key in accountMap) {
105
- if (Object.prototype.hasOwnProperty.call(accountMap, key)) {
106
- data[key] = account[accountMap[key]];
107
- }
108
- } // eslint-disable-next-line no-restricted-syntax
109
-
110
-
111
- for (const key in profileMap) {
112
- if (Object.prototype.hasOwnProperty.call(profileMap, key)) {
113
- data[key] = profile[profileMap[key]];
114
- }
115
- }
120
+ const data = _objectSpread({
121
+ [identityField]: identity
122
+ }, userInput);
116
123
 
117
124
  if (!result.success) {
118
125
  if (!autoCreate) {
@@ -49,23 +49,42 @@ async function validateNextAuth(identityField, identity, protectIdentities, item
49
49
 
50
50
  function NextAuthPage(props) {
51
51
  const {
52
+ autoCreate,
53
+ cookies,
54
+ events,
55
+ identityField,
56
+ jwt,
57
+ listKey,
58
+ pages,
52
59
  providers,
53
60
  query,
54
- identityField,
61
+ resolver,
55
62
  sessionData,
56
- listKey,
57
- autoCreate,
58
- userMap,
59
- accountMap,
60
- profileMap,
61
63
  sessionSecret
62
- } = props;
64
+ } = props; // TODO: (v1.1). https://github.com/ijsto/keystone-6-oauth/projects/1#card-78602004
65
+
66
+ console.log('NextAuthPages... ', pages);
67
+
68
+ if (!query) {
69
+ console.error('NextAuthPage got no query.');
70
+ return null;
71
+ }
72
+
73
+ if (!providers || !providers.length) {
74
+ console.error('You need to provide at least one provider.');
75
+ return null;
76
+ }
77
+
63
78
  const list = query[listKey];
64
79
  const queryAPI = query[listKey];
65
80
  const protectIdentities = true;
66
81
  return NextAuth({
67
- secret: sessionSecret,
82
+ cookies,
68
83
  providers,
84
+ pages: pages || {},
85
+ events: events || {},
86
+ jwt: jwt || {},
87
+ secret: sessionSecret,
69
88
  callbacks: {
70
89
  async signIn({
71
90
  user,
@@ -82,28 +101,16 @@ function NextAuthPage(props) {
82
101
  identity = 0;
83
102
  }
84
103
 
85
- const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
86
- const data = {}; // eslint-disable-next-line no-restricted-syntax
87
-
88
- for (const key in userMap) {
89
- if (Object.prototype.hasOwnProperty.call(userMap, key)) {
90
- data[key] = user[userMap[key]];
91
- }
92
- } // eslint-disable-next-line no-restricted-syntax
93
-
104
+ const userInput = resolver ? await resolver({
105
+ user,
106
+ account,
107
+ profile
108
+ }) : {};
109
+ const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI); // ID
94
110
 
95
- for (const key in accountMap) {
96
- if (Object.prototype.hasOwnProperty.call(accountMap, key)) {
97
- data[key] = account[accountMap[key]];
98
- }
99
- } // eslint-disable-next-line no-restricted-syntax
100
-
101
-
102
- for (const key in profileMap) {
103
- if (Object.prototype.hasOwnProperty.call(profileMap, key)) {
104
- data[key] = profile[profileMap[key]];
105
- }
106
- }
111
+ const data = _objectSpread({
112
+ [identityField]: identity
113
+ }, userInput);
107
114
 
108
115
  if (!result.success) {
109
116
  if (!autoCreate) {
@@ -1,15 +1,11 @@
1
1
  import type { BaseItem } from '@keystone-6/core/types';
2
2
  import { graphql } from '@keystone-6/core';
3
3
 
4
- import { AuthGqlNames } from '../types';
5
-
6
4
  export function getBaseAuthSchema({
7
5
  listKey,
8
- gqlNames,
9
6
  base,
10
7
  }: {
11
8
  listKey: string;
12
- gqlNames: AuthGqlNames;
13
9
  base: graphql.BaseSchemaMeta;
14
10
  }) {
15
11
  const extension = {