@opensaas/keystone-nextjs-auth 15.0.0 → 18.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.
@@ -13,9 +13,9 @@ var client = require('next-auth/client');
13
13
  var Providers = require('next-auth/providers');
14
14
  var cookie = require('cookie');
15
15
  var ejs = require('ejs');
16
- var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
17
16
  var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
18
- var merge = require('@graphql-tools/merge');
17
+ var graphql = require('graphql');
18
+ var keystone = require('@keystone-next/keystone');
19
19
 
20
20
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
21
21
 
@@ -28,14 +28,12 @@ function _interopNamespace(e) {
28
28
  var d = Object.getOwnPropertyDescriptor(e, k);
29
29
  Object.defineProperty(n, k, d.get ? d : {
30
30
  enumerable: true,
31
- get: function () {
32
- return e[k];
33
- }
31
+ get: function () { return e[k]; }
34
32
  });
35
33
  }
36
34
  });
37
35
  }
38
- n['default'] = e;
36
+ n["default"] = e;
39
37
  return Object.freeze(n);
40
38
  }
41
39
 
@@ -47,7 +45,6 @@ var url__default = /*#__PURE__*/_interopDefault(url);
47
45
  var Providers__default = /*#__PURE__*/_interopDefault(Providers);
48
46
  var cookie__namespace = /*#__PURE__*/_interopNamespace(cookie);
49
47
  var ejs__default = /*#__PURE__*/_interopDefault(ejs);
50
- var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
51
48
  var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
52
49
 
53
50
  const template$1 = `
@@ -77,16 +74,36 @@ module.exports = withPreconstruct({
77
74
  /@keystone-next\\/keystone(?!\\/___internal-do-not-use-will-break-in-patch\\/admin-ui\\/id-field-view|\\/fields\\/types\\/[^\\/]+\\/views)/,
78
75
  /.prisma\\/client/
79
76
  ];
77
+ // we need to set these to true so that when __dirname/__filename is used
78
+ // to resolve the location of field views, we will get a path that we can use
79
+ // rather than just the __dirname/__filename of the generated file.
80
+ // https://webpack.js.org/configuration/node/#node__filename
81
+ (_config$node = config.node) !== null && _config$node !== void 0 ? _config$node : config.node = {};
82
+ config.node.__dirname = true;
83
+ config.node.__filename = true;
80
84
  }
81
85
  return config;
82
86
  },
87
+ <% if (keystonePath) { %>
88
+ <% if (process.env.NODE_ENV != 'production') { %>
89
+ async rewrites() {
90
+ return [
91
+ {
92
+ source: '/api/__keystone_api_build',
93
+ destination: 'http://localhost:3000<%= keystonePath || '' %>/api/__keystone_api_build',
94
+ basePath: false
95
+ }
96
+ ];
97
+ },
98
+ <% }%>
83
99
  basePath: '<%= keystonePath || '' %>'
100
+ <% } %>
84
101
  });
85
102
  `;
86
103
  const nextConfigTemplate = ({
87
104
  keystonePath
88
105
  }) => {
89
- const nextConfigOut = ejs__default['default'].render(template$1, {
106
+ const nextConfigOut = ejs__default["default"].render(template$1, {
90
107
  keystonePath
91
108
  });
92
109
  return nextConfigOut;
@@ -94,82 +111,74 @@ const nextConfigTemplate = ({
94
111
 
95
112
  function getBaseAuthSchema({
96
113
  listKey,
97
- gqlNames
114
+ gqlNames,
115
+ base
98
116
  }) {
99
- return {
100
- typeDefs: `
101
- # Auth
102
- union AuthenticatedItem = ${listKey}
103
- type Query {
104
- authenticatedItem: AuthenticatedItem
105
- }
106
- `,
107
- resolvers: {
108
- Query: {
109
- async authenticatedItem(root, args, {
117
+ const extension = {
118
+ query: {
119
+ authenticatedItem: keystone.graphql.field({
120
+ type: keystone.graphql.union({
121
+ name: 'AuthenticatedItem',
122
+ types: [base.object(listKey)],
123
+ resolveType: (root, context) => {
124
+ var _context$session;
125
+
126
+ return (_context$session = context.session) === null || _context$session === void 0 ? void 0 : _context$session.listKey;
127
+ }
128
+ }),
129
+
130
+ resolve(root, args, {
110
131
  session,
111
- query
132
+ db
112
133
  }) {
113
134
  if (typeof (session === null || session === void 0 ? void 0 : session.itemId) === 'string' && typeof session.listKey === 'string') {
114
- try {
115
- return query[session.listKey].findOne({
116
- where: {
117
- id: session.itemId
118
- },
119
- resolveFields: false
120
- });
121
- } catch (e) {
122
- return null;
123
- }
135
+ return db[session.listKey].findOne({
136
+ where: {
137
+ id: session.itemId
138
+ }
139
+ });
124
140
  }
125
141
 
126
142
  return null;
127
143
  }
128
144
 
129
- },
130
- AuthenticatedItem: {
131
- __resolveType(rootVal, {
132
- session
133
- }) {
134
- return session === null || session === void 0 ? void 0 : session.listKey;
135
- }
136
-
137
- },
138
- // TODO: Is this the preferred approach for this?
139
- [gqlNames.ItemAuthenticationWithPasswordResult]: {
140
- __resolveType(rootVal) {
141
- return rootVal.sessionToken ? gqlNames.ItemAuthenticationWithPasswordSuccess : gqlNames.ItemAuthenticationWithPasswordFailure;
142
- }
143
-
144
- }
145
+ })
145
146
  }
146
147
  };
148
+ return {
149
+ extension
150
+ };
147
151
  }
148
152
 
149
153
  const getSchemaExtension = ({
150
154
  identityField,
151
155
  listKey,
152
156
  gqlNames
153
- }) => schema => {
154
- var _context, _context2;
157
+ }) => keystone.graphql.extend(base => {
158
+ var _context;
159
+
160
+ const uniqueWhereInputType = graphql.assertInputObjectType(base.schema.getType(`${listKey}WhereUniqueInput`));
161
+ const identityFieldOnUniqueWhere = uniqueWhereInputType.getFields()[identityField];
162
+
163
+ if ((identityFieldOnUniqueWhere === null || identityFieldOnUniqueWhere === void 0 ? void 0 : identityFieldOnUniqueWhere.type) !== graphql.GraphQLString && (identityFieldOnUniqueWhere === null || identityFieldOnUniqueWhere === void 0 ? void 0 : identityFieldOnUniqueWhere.type) !== graphql.GraphQLID) {
164
+ 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}`);
165
+ }
155
166
 
156
- return _reduceInstanceProperty__default['default'](_context = _filterInstanceProperty__default['default'](_context2 = [getBaseAuthSchema({
167
+ const baseSchema = getBaseAuthSchema({
157
168
  listKey,
158
- gqlNames
159
- })]).call(_context2, x => x)).call(_context, (s, extension) => merge.mergeSchemas(_objectSpread({
160
- schemas: [s]
161
- }, extension)), schema);
162
- };
169
+ gqlNames,
170
+ base
171
+ });
172
+ return _filterInstanceProperty__default["default"](_context = [baseSchema.extension]).call(_context, x => x !== undefined);
173
+ });
163
174
 
164
175
  const template = `
165
176
  import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
166
- import { nextAuthProviders as Providers } from '@opensaas/keystone-nextjs-auth';
167
177
  import { query } from '.keystone/api';
168
178
  import keystoneConfig from '../../../../../keystone';
169
179
 
170
180
  export default getNextAuthPage({
171
181
  identityField: '<%= identityField %>',
172
- mutationName: '<%= gqlNames.authenticateItemWithPassword %>',
173
182
  sessionData: '<%= sessionData %>',
174
183
  listKey: '<%= listKey %>',
175
184
  userMap: <%- JSON.stringify(userMap) %>,
@@ -190,7 +199,7 @@ const authTemplate = ({
190
199
  accountMap,
191
200
  profileMap
192
201
  }) => {
193
- const authOut = ejs__default['default'].render(template, {
202
+ const authOut = ejs__default["default"].render(template, {
194
203
  gqlNames,
195
204
  identityField,
196
205
  sessionData,
@@ -204,7 +213,7 @@ const authTemplate = ({
204
213
  };
205
214
 
206
215
  const _excluded = ["get"];
207
- const nextAuthProviders = Providers__default['default'];
216
+ const nextAuthProviders = Providers__default["default"];
208
217
  /**
209
218
  * createAuth function
210
219
  *
@@ -256,7 +265,7 @@ function createAuth({
256
265
  req,
257
266
  session
258
267
  } = context;
259
- const pathname = url__default['default'].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
268
+ const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
260
269
 
261
270
  if (isValidSession) {
262
271
  if (pathname === `${customPath}/api/auth/signin`) {
@@ -269,7 +278,7 @@ function createAuth({
269
278
  return;
270
279
  }
271
280
 
272
- if (!session && !_includesInstanceProperty__default['default'](pathname).call(pathname, `${customPath}/api/auth/`)) {
281
+ if (!session && !_includesInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/api/auth/`)) {
273
282
  return {
274
283
  kind: 'redirect',
275
284
  to: `${customPath}/api/auth/signin`
@@ -324,7 +333,7 @@ function createAuth({
324
333
  publicPages.push(`${customPath}/api/auth/callback/${name}`);
325
334
  }
326
335
 
327
- _mapInstanceProperty__default['default'](providers).call(providers, addPages);
336
+ _mapInstanceProperty__default["default"](providers).call(providers, addPages);
328
337
  /**
329
338
  * extendGraphqlSchema
330
339
  *
@@ -357,7 +366,7 @@ function createAuth({
357
366
  const identityFieldConfig = listConfig.fields[identityField];
358
367
 
359
368
  if (identityFieldConfig === undefined) {
360
- const i = _JSON$stringify__default['default'](identityField);
369
+ const i = _JSON$stringify__default["default"](identityField);
361
370
 
362
371
  const msg = `A createAuth() invocation for the "${listKey}" list specifies ${i} as its identityField but no field with that key exists on the list.`;
363
372
  throw new Error(msg);
@@ -381,9 +390,9 @@ function createAuth({
381
390
  get: async ({
382
391
  req
383
392
  }) => {
384
- const pathname = url__default['default'].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
393
+ const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
385
394
 
386
- if (_includesInstanceProperty__default['default'](pathname).call(pathname, '/api/auth')) {
395
+ if (_includesInstanceProperty__default["default"](pathname).call(pathname, '/api/auth')) {
387
396
  return;
388
397
  }
389
398
 
@@ -407,7 +416,7 @@ function createAuth({
407
416
  secure: "production" === 'production',
408
417
  path: '/',
409
418
  sameSite: 'lax',
410
- domain: url__default['default'].parse(req.url).hostname
419
+ domain: url__default["default"].parse(req.url).hostname
411
420
  }));
412
421
  }
413
422
  });
@@ -431,37 +440,33 @@ function createAuth({
431
440
  } = keystoneConfig;
432
441
 
433
442
  if (keystoneConfig.ui) {
443
+ var _keystoneConfig$ui;
444
+
434
445
  ui = _objectSpread(_objectSpread({}, keystoneConfig.ui), {}, {
435
446
  publicPages: [...(keystoneConfig.ui.publicPages || []), ...publicPages],
436
- getAdditionalFiles: [...(keystoneConfig.ui.getAdditionalFiles || []), getAdditionalFiles],
447
+ getAdditionalFiles: [...(((_keystoneConfig$ui = keystoneConfig.ui) === null || _keystoneConfig$ui === void 0 ? void 0 : _keystoneConfig$ui.getAdditionalFiles) || []), getAdditionalFiles],
437
448
  pageMiddleware: async args => {
438
- var _await$pageMiddleware, _keystoneConfig$ui, _keystoneConfig$ui$pa;
449
+ var _await$pageMiddleware, _keystoneConfig$ui2, _keystoneConfig$ui2$p;
439
450
 
440
- return (_await$pageMiddleware = await pageMiddleware(args)) !== null && _await$pageMiddleware !== void 0 ? _await$pageMiddleware : keystoneConfig === null || keystoneConfig === void 0 ? void 0 : (_keystoneConfig$ui = keystoneConfig.ui) === null || _keystoneConfig$ui === void 0 ? void 0 : (_keystoneConfig$ui$pa = _keystoneConfig$ui.pageMiddleware) === null || _keystoneConfig$ui$pa === void 0 ? void 0 : _keystoneConfig$ui$pa.call(_keystoneConfig$ui, args);
451
+ return (_await$pageMiddleware = await pageMiddleware(args)) !== null && _await$pageMiddleware !== void 0 ? _await$pageMiddleware : 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);
441
452
  },
442
453
  enableSessionItem: true,
443
454
  isAccessAllowed: async context => {
444
- var _context$req, _keystoneConfig$ui2;
455
+ var _context$req, _keystoneConfig$ui3;
445
456
 
446
457
  // Allow access to the adminMeta data from the /init path to correctly render that page
447
458
  // even if the user isn't logged in (which should always be the case if they're seeing /init)
448
459
  const headers = (_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.headers;
449
460
  const host = headers ? headers['x-forwarded-host'] || headers.host : null;
450
- const thisUrl = headers !== null && headers !== void 0 && headers.referer ? new _URL__default['default'](headers.referer) : undefined;
461
+ const thisUrl = headers !== null && headers !== void 0 && headers.referer ? new _URL__default["default"](headers.referer) : undefined;
451
462
  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;
452
- return accessingInitPage || ((_keystoneConfig$ui2 = keystoneConfig.ui) !== null && _keystoneConfig$ui2 !== void 0 && _keystoneConfig$ui2.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined);
463
+ return accessingInitPage || ((_keystoneConfig$ui3 = keystoneConfig.ui) !== null && _keystoneConfig$ui3 !== void 0 && _keystoneConfig$ui3.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined);
453
464
  }
454
465
  });
455
466
  }
456
467
 
457
- let {
458
- session
459
- } = keystoneConfig;
460
-
461
- if (session && sessionData) {
462
- session = withItemData(session);
463
- }
464
-
468
+ if (!keystoneConfig.session) throw new TypeError('Missing .session configuration');
469
+ const session = withItemData(keystoneConfig.session);
465
470
  const existingExtendGraphQLSchema = keystoneConfig.extendGraphqlSchema;
466
471
  return _objectSpread(_objectSpread({}, keystoneConfig), {}, {
467
472
  ui,
@@ -9,9 +9,9 @@ import { getSession } from 'next-auth/client';
9
9
  import Providers from 'next-auth/providers';
10
10
  import * as cookie from 'cookie';
11
11
  import ejs from 'ejs';
12
- import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
13
12
  import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
14
- import { mergeSchemas } from '@graphql-tools/merge';
13
+ import { assertInputObjectType, GraphQLString, GraphQLID } from 'graphql';
14
+ import { graphql } from '@keystone-next/keystone';
15
15
 
16
16
  const template$1 = `
17
17
  const Path = require('path');
@@ -40,10 +40,30 @@ module.exports = withPreconstruct({
40
40
  /@keystone-next\\/keystone(?!\\/___internal-do-not-use-will-break-in-patch\\/admin-ui\\/id-field-view|\\/fields\\/types\\/[^\\/]+\\/views)/,
41
41
  /.prisma\\/client/
42
42
  ];
43
+ // we need to set these to true so that when __dirname/__filename is used
44
+ // to resolve the location of field views, we will get a path that we can use
45
+ // rather than just the __dirname/__filename of the generated file.
46
+ // https://webpack.js.org/configuration/node/#node__filename
47
+ (_config$node = config.node) !== null && _config$node !== void 0 ? _config$node : config.node = {};
48
+ config.node.__dirname = true;
49
+ config.node.__filename = true;
43
50
  }
44
51
  return config;
45
52
  },
53
+ <% if (keystonePath) { %>
54
+ <% if (process.env.NODE_ENV != 'production') { %>
55
+ async rewrites() {
56
+ return [
57
+ {
58
+ source: '/api/__keystone_api_build',
59
+ destination: 'http://localhost:3000<%= keystonePath || '' %>/api/__keystone_api_build',
60
+ basePath: false
61
+ }
62
+ ];
63
+ },
64
+ <% }%>
46
65
  basePath: '<%= keystonePath || '' %>'
66
+ <% } %>
47
67
  });
48
68
  `;
49
69
  const nextConfigTemplate = ({
@@ -57,82 +77,74 @@ const nextConfigTemplate = ({
57
77
 
58
78
  function getBaseAuthSchema({
59
79
  listKey,
60
- gqlNames
80
+ gqlNames,
81
+ base
61
82
  }) {
62
- return {
63
- typeDefs: `
64
- # Auth
65
- union AuthenticatedItem = ${listKey}
66
- type Query {
67
- authenticatedItem: AuthenticatedItem
68
- }
69
- `,
70
- resolvers: {
71
- Query: {
72
- async authenticatedItem(root, args, {
83
+ const extension = {
84
+ query: {
85
+ authenticatedItem: graphql.field({
86
+ type: graphql.union({
87
+ name: 'AuthenticatedItem',
88
+ types: [base.object(listKey)],
89
+ resolveType: (root, context) => {
90
+ var _context$session;
91
+
92
+ return (_context$session = context.session) === null || _context$session === void 0 ? void 0 : _context$session.listKey;
93
+ }
94
+ }),
95
+
96
+ resolve(root, args, {
73
97
  session,
74
- query
98
+ db
75
99
  }) {
76
100
  if (typeof (session === null || session === void 0 ? void 0 : session.itemId) === 'string' && typeof session.listKey === 'string') {
77
- try {
78
- return query[session.listKey].findOne({
79
- where: {
80
- id: session.itemId
81
- },
82
- resolveFields: false
83
- });
84
- } catch (e) {
85
- return null;
86
- }
101
+ return db[session.listKey].findOne({
102
+ where: {
103
+ id: session.itemId
104
+ }
105
+ });
87
106
  }
88
107
 
89
108
  return null;
90
109
  }
91
110
 
92
- },
93
- AuthenticatedItem: {
94
- __resolveType(rootVal, {
95
- session
96
- }) {
97
- return session === null || session === void 0 ? void 0 : session.listKey;
98
- }
99
-
100
- },
101
- // TODO: Is this the preferred approach for this?
102
- [gqlNames.ItemAuthenticationWithPasswordResult]: {
103
- __resolveType(rootVal) {
104
- return rootVal.sessionToken ? gqlNames.ItemAuthenticationWithPasswordSuccess : gqlNames.ItemAuthenticationWithPasswordFailure;
105
- }
106
-
107
- }
111
+ })
108
112
  }
109
113
  };
114
+ return {
115
+ extension
116
+ };
110
117
  }
111
118
 
112
119
  const getSchemaExtension = ({
113
120
  identityField,
114
121
  listKey,
115
122
  gqlNames
116
- }) => schema => {
117
- var _context, _context2;
123
+ }) => graphql.extend(base => {
124
+ var _context;
125
+
126
+ const uniqueWhereInputType = assertInputObjectType(base.schema.getType(`${listKey}WhereUniqueInput`));
127
+ const identityFieldOnUniqueWhere = uniqueWhereInputType.getFields()[identityField];
128
+
129
+ if ((identityFieldOnUniqueWhere === null || identityFieldOnUniqueWhere === void 0 ? void 0 : identityFieldOnUniqueWhere.type) !== GraphQLString && (identityFieldOnUniqueWhere === null || identityFieldOnUniqueWhere === void 0 ? void 0 : identityFieldOnUniqueWhere.type) !== GraphQLID) {
130
+ 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}`);
131
+ }
118
132
 
119
- return _reduceInstanceProperty(_context = _filterInstanceProperty(_context2 = [getBaseAuthSchema({
133
+ const baseSchema = getBaseAuthSchema({
120
134
  listKey,
121
- gqlNames
122
- })]).call(_context2, x => x)).call(_context, (s, extension) => mergeSchemas(_objectSpread({
123
- schemas: [s]
124
- }, extension)), schema);
125
- };
135
+ gqlNames,
136
+ base
137
+ });
138
+ return _filterInstanceProperty(_context = [baseSchema.extension]).call(_context, x => x !== undefined);
139
+ });
126
140
 
127
141
  const template = `
128
142
  import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
129
- import { nextAuthProviders as Providers } from '@opensaas/keystone-nextjs-auth';
130
143
  import { query } from '.keystone/api';
131
144
  import keystoneConfig from '../../../../../keystone';
132
145
 
133
146
  export default getNextAuthPage({
134
147
  identityField: '<%= identityField %>',
135
- mutationName: '<%= gqlNames.authenticateItemWithPassword %>',
136
148
  sessionData: '<%= sessionData %>',
137
149
  listKey: '<%= listKey %>',
138
150
  userMap: <%- JSON.stringify(userMap) %>,
@@ -394,17 +406,19 @@ function createAuth({
394
406
  } = keystoneConfig;
395
407
 
396
408
  if (keystoneConfig.ui) {
409
+ var _keystoneConfig$ui;
410
+
397
411
  ui = _objectSpread(_objectSpread({}, keystoneConfig.ui), {}, {
398
412
  publicPages: [...(keystoneConfig.ui.publicPages || []), ...publicPages],
399
- getAdditionalFiles: [...(keystoneConfig.ui.getAdditionalFiles || []), getAdditionalFiles],
413
+ getAdditionalFiles: [...(((_keystoneConfig$ui = keystoneConfig.ui) === null || _keystoneConfig$ui === void 0 ? void 0 : _keystoneConfig$ui.getAdditionalFiles) || []), getAdditionalFiles],
400
414
  pageMiddleware: async args => {
401
- var _await$pageMiddleware, _keystoneConfig$ui, _keystoneConfig$ui$pa;
415
+ var _await$pageMiddleware, _keystoneConfig$ui2, _keystoneConfig$ui2$p;
402
416
 
403
- return (_await$pageMiddleware = await pageMiddleware(args)) !== null && _await$pageMiddleware !== void 0 ? _await$pageMiddleware : keystoneConfig === null || keystoneConfig === void 0 ? void 0 : (_keystoneConfig$ui = keystoneConfig.ui) === null || _keystoneConfig$ui === void 0 ? void 0 : (_keystoneConfig$ui$pa = _keystoneConfig$ui.pageMiddleware) === null || _keystoneConfig$ui$pa === void 0 ? void 0 : _keystoneConfig$ui$pa.call(_keystoneConfig$ui, args);
417
+ return (_await$pageMiddleware = await pageMiddleware(args)) !== null && _await$pageMiddleware !== void 0 ? _await$pageMiddleware : 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);
404
418
  },
405
419
  enableSessionItem: true,
406
420
  isAccessAllowed: async context => {
407
- var _context$req, _keystoneConfig$ui2;
421
+ var _context$req, _keystoneConfig$ui3;
408
422
 
409
423
  // Allow access to the adminMeta data from the /init path to correctly render that page
410
424
  // even if the user isn't logged in (which should always be the case if they're seeing /init)
@@ -412,19 +426,13 @@ function createAuth({
412
426
  const host = headers ? headers['x-forwarded-host'] || headers.host : null;
413
427
  const thisUrl = headers !== null && headers !== void 0 && headers.referer ? new _URL(headers.referer) : undefined;
414
428
  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;
415
- return accessingInitPage || ((_keystoneConfig$ui2 = keystoneConfig.ui) !== null && _keystoneConfig$ui2 !== void 0 && _keystoneConfig$ui2.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined);
429
+ return accessingInitPage || ((_keystoneConfig$ui3 = keystoneConfig.ui) !== null && _keystoneConfig$ui3 !== void 0 && _keystoneConfig$ui3.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined);
416
430
  }
417
431
  });
418
432
  }
419
433
 
420
- let {
421
- session
422
- } = keystoneConfig;
423
-
424
- if (session && sessionData) {
425
- session = withItemData(session);
426
- }
427
-
434
+ if (!keystoneConfig.session) throw new TypeError('Missing .session configuration');
435
+ const session = withItemData(keystoneConfig.session);
428
436
  const existingExtendGraphQLSchema = keystoneConfig.extendGraphqlSchema;
429
437
  return _objectSpread(_objectSpread({}, keystoneConfig), {}, {
430
438
  ui,
package/package.json CHANGED
@@ -1,28 +1,28 @@
1
1
  {
2
2
  "name": "@opensaas/keystone-nextjs-auth",
3
- "version": "15.0.0",
3
+ "version": "18.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.15.4",
10
- "@babel/runtime-corejs3": "^7.15.3",
11
- "@graphql-tools/merge": "^6.2.14",
9
+ "@babel/runtime": "^7.15.8",
10
+ "@babel/runtime-corejs3": "^7.15.4",
12
11
  "@keystone-next/admin-ui-utils": "^6.0.0",
13
- "@types/ejs": "^3.0.6",
12
+ "@types/ejs": "^3.1.0",
14
13
  "cookie": "^0.4.1",
15
14
  "cross-fetch": "^3.1.4",
16
15
  "ejs": "^3.1.6",
17
16
  "fast-deep-equal": "^3.1.3",
17
+ "graphql": "^15.6.1",
18
18
  "next-auth": "^3.29.0"
19
19
  },
20
20
  "devDependencies": {
21
- "@keystone-next/keystone": "^26.1.1",
21
+ "@keystone-next/keystone": "^29.0.0",
22
22
  "react": "^17.0.2"
23
23
  },
24
24
  "peerDependencies": {
25
- "@keystone-next/keystone": "^26.1.1",
25
+ "@keystone-next/keystone": "^29.0.0",
26
26
  "react": "^17.0.2"
27
27
  },
28
28
  "engines": {
@@ -13,10 +13,8 @@ async function findMatchingIdentity(identityField, identity, queryAPI) {
13
13
  const item = await queryAPI.findOne({
14
14
  where: {
15
15
  [identityField]: identity
16
- },
17
- resolveFields: false
18
- });
19
- console.log(item); // Identity failures with helpful errors
16
+ }
17
+ }); // Identity failures with helpful errors
20
18
 
21
19
  let code;
22
20
 
@@ -71,7 +69,7 @@ function NextAuthPage(props) {
71
69
  const list = query[listKey];
72
70
  const queryAPI = query[listKey];
73
71
  const protectIdentities = true;
74
- return NextAuth__default['default']({
72
+ return NextAuth__default["default"]({
75
73
  providers,
76
74
  callbacks: {
77
75
  async signIn(user, account, profile) {
@@ -128,13 +126,11 @@ function NextAuthPage(props) {
128
126
  }
129
127
  },
130
128
 
131
- async redirect(url, baseUrl) {
129
+ async redirect(url) {
132
130
  return url;
133
131
  },
134
132
 
135
133
  async session(session, token) {
136
- console.log('session:', session);
137
-
138
134
  const returnSession = _objectSpread(_objectSpread({}, session), {}, {
139
135
  data: token.data,
140
136
  subject: token.sub,
@@ -145,8 +141,7 @@ function NextAuthPage(props) {
145
141
  return returnSession;
146
142
  },
147
143
 
148
- async jwt(token, user, account, profile, isNewUser) {
149
- console.log('account:', account);
144
+ async jwt(token) {
150
145
  const identity = token.sub;
151
146
 
152
147
  if (!token.itemId) {
@@ -181,5 +176,5 @@ function NextAuthPage(props) {
181
176
  }
182
177
  const getNextAuthPage = props => () => NextAuthPage(_objectSpread({}, props));
183
178
 
184
- exports['default'] = NextAuthPage;
179
+ exports["default"] = NextAuthPage;
185
180
  exports.getNextAuthPage = getNextAuthPage;