@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @opensaas-keystone/nextjs-auth
2
2
 
3
+ ## 18.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - cff5031: Upgrade to `"@keystone-next/keystone": "^29.0.0"` see https://keystonejs.com/releases/2021-11-24 for more information
8
+
9
+ ## 17.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - c619df8: Upgrade to `"@keystone-next/keystone": "28.0.0"`
14
+
15
+ ## 16.0.1
16
+
17
+ ### Patch Changes
18
+
19
+ - 2e3ae54: Fix Nullish coalescing operator in next-config for older versions of node
20
+
21
+ ## 16.0.0
22
+
23
+ ### Major Changes
24
+
25
+ - eaea6af: Upgrade to Keystone 27
26
+
3
27
  ## 15.0.0
4
28
 
5
29
  ### Major Changes
@@ -1,6 +1,14 @@
1
- import type { GraphQLSchemaExtension } from '@keystone-next/keystone/types';
2
- import { AuthGqlNames } from '../types';
3
- export declare function getBaseAuthSchema<I extends string, S extends string>({ listKey, gqlNames, }: {
4
- listKey: string;
5
- gqlNames: AuthGqlNames;
6
- }): GraphQLSchemaExtension;
1
+ import type { ItemRootValue } from '@keystone-next/keystone/types';
2
+ import { graphql } from '@keystone-next/keystone';
3
+ import { AuthGqlNames } from '../types';
4
+ export declare function getBaseAuthSchema({ listKey, gqlNames, base, }: {
5
+ listKey: string;
6
+ gqlNames: AuthGqlNames;
7
+ base: graphql.BaseSchemaMeta;
8
+ }): {
9
+ extension: {
10
+ query: {
11
+ authenticatedItem: import("@graphql-ts/schema").Field<unknown, {}, import("@graphql-ts/schema").UnionType<ItemRootValue, import("@keystone-next/keystone/types").KeystoneContext>, string, import("@keystone-next/keystone/types").KeystoneContext>;
12
+ };
13
+ };
14
+ };
@@ -1,12 +1,12 @@
1
- import { BaseGeneratedListTypes, KeystoneConfig } from '@keystone-next/keystone/types';
2
- import { AuthConfig, KeystoneAuthConfig } from './types';
3
- export declare const nextAuthProviders: import("next-auth/providers").BuiltInProviders;
4
- /**
5
- * createAuth function
6
- *
7
- * Generates config for Keystone to implement standard auth features.
8
- */
9
- export type { NextAuthProviders, KeystoneAuthConfig } from './types';
10
- export declare function createAuth<GeneratedListTypes extends BaseGeneratedListTypes>({ listKey, identityField, sessionData, autoCreate, userMap, accountMap, profileMap, keystonePath, providers, }: AuthConfig<GeneratedListTypes>): {
11
- withAuth: (keystoneConfig: KeystoneConfig) => KeystoneAuthConfig;
12
- };
1
+ import { BaseGeneratedListTypes, KeystoneConfig } from '@keystone-next/keystone/types';
2
+ import { AuthConfig, KeystoneAuthConfig } from './types';
3
+ export declare const nextAuthProviders: import("next-auth/providers").BuiltInProviders;
4
+ /**
5
+ * createAuth function
6
+ *
7
+ * Generates config for Keystone to implement standard auth features.
8
+ */
9
+ export type { NextAuthProviders, KeystoneAuthConfig } from './types';
10
+ export declare function createAuth<GeneratedListTypes extends BaseGeneratedListTypes>({ listKey, identityField, sessionData, autoCreate, userMap, accountMap, profileMap, keystonePath, providers, }: AuthConfig<GeneratedListTypes>): {
11
+ withAuth: (keystoneConfig: KeystoneConfig) => KeystoneAuthConfig;
12
+ };
@@ -1,8 +1,8 @@
1
- import { AuthTokenRequestErrorCode } from '../types';
2
- export declare function findMatchingIdentity(identityField: string, identity: string | number, queryAPI: any): Promise<{
3
- success: false;
4
- code: AuthTokenRequestErrorCode;
5
- } | {
6
- success: true;
7
- item: any;
8
- }>;
1
+ import { AuthTokenRequestErrorCode } from '../types';
2
+ export declare function findMatchingIdentity(identityField: string, identity: string | number, queryAPI: any): Promise<{
3
+ success: false;
4
+ code: AuthTokenRequestErrorCode;
5
+ } | {
6
+ success: true;
7
+ item: any;
8
+ }>;
@@ -1,12 +1,12 @@
1
- import type { KeystoneListsAPI } from '@keystone-next/keystone/types';
2
- import { NextAuthErrorCode } from '../types';
3
- export declare function validateNextAuth(list: any, identityField: string, identity: string | number, protectIdentities: boolean, itemAPI: KeystoneListsAPI<any>[string]): Promise<{
4
- success: false;
5
- code: NextAuthErrorCode;
6
- } | {
7
- success: true;
8
- item: {
9
- id: any;
10
- [prop: string]: any;
11
- };
12
- }>;
1
+ import type { KeystoneListsAPI } from '@keystone-next/keystone/types';
2
+ import { NextAuthErrorCode } from '../types';
3
+ export declare function validateNextAuth(list: any, identityField: string, identity: string | number, protectIdentities: boolean, itemAPI: KeystoneListsAPI<any>[string]): Promise<{
4
+ success: false;
5
+ code: NextAuthErrorCode;
6
+ } | {
7
+ success: true;
8
+ item: {
9
+ id: any;
10
+ [prop: string]: any;
11
+ };
12
+ }>;
@@ -1,17 +1,17 @@
1
- import { Provider } from 'next-auth/providers';
2
- import type { KeystoneListsAPI } from '@keystone-next/keystone/types';
3
- declare type NextAuthPageProps = {
4
- identityField: string;
5
- mutationName: string;
6
- providers: Provider[];
7
- query: KeystoneListsAPI<any>;
8
- sessionData: string;
9
- listKey: string;
10
- autoCreate: boolean;
11
- userMap: any;
12
- accountMap: any;
13
- profileMap: any;
14
- };
15
- export default function NextAuthPage(props: NextAuthPageProps): void | Promise<void>;
16
- export declare const getNextAuthPage: (props: NextAuthPageProps) => () => void | Promise<void>;
17
- export {};
1
+ import { Provider } from 'next-auth/providers';
2
+ import type { KeystoneListsAPI } from '@keystone-next/keystone/types';
3
+ declare type NextAuthPageProps = {
4
+ identityField: string;
5
+ mutationName: string;
6
+ providers: Provider[];
7
+ query: KeystoneListsAPI<any>;
8
+ sessionData: string;
9
+ listKey: string;
10
+ autoCreate: boolean;
11
+ userMap: any;
12
+ accountMap: any;
13
+ profileMap: any;
14
+ };
15
+ export default function NextAuthPage(props: NextAuthPageProps): void | Promise<void>;
16
+ export declare const getNextAuthPage: (props: NextAuthPageProps) => () => void | Promise<void>;
17
+ export {};
@@ -1,7 +1,7 @@
1
- import { ExtendGraphqlSchema } from '@keystone-next/keystone/types';
2
- import { AuthGqlNames } from './types';
3
- export declare const getSchemaExtension: ({ identityField, listKey, gqlNames, }: {
4
- identityField: string;
5
- listKey: string;
6
- gqlNames: AuthGqlNames;
7
- }) => ExtendGraphqlSchema;
1
+ import { ExtendGraphqlSchema } from '@keystone-next/keystone/types';
2
+ import { AuthGqlNames } from './types';
3
+ export declare const getSchemaExtension: ({ identityField, listKey, gqlNames, }: {
4
+ identityField: string;
5
+ listKey: string;
6
+ gqlNames: AuthGqlNames;
7
+ }) => ExtendGraphqlSchema;
@@ -1,11 +1,11 @@
1
- import { AuthGqlNames } from '../types';
2
- export declare const authTemplate: ({ gqlNames, identityField, sessionData, listKey, autoCreate, userMap, accountMap, profileMap, }: {
3
- gqlNames: AuthGqlNames;
4
- identityField: string;
5
- sessionData: any;
6
- listKey: string;
7
- autoCreate: boolean;
8
- userMap: any;
9
- accountMap: any;
10
- profileMap: any;
11
- }) => string;
1
+ import { AuthGqlNames } from '../types';
2
+ export declare const authTemplate: ({ gqlNames, identityField, sessionData, listKey, autoCreate, userMap, accountMap, profileMap, }: {
3
+ gqlNames: AuthGqlNames;
4
+ identityField: string;
5
+ sessionData: any;
6
+ listKey: string;
7
+ autoCreate: boolean;
8
+ userMap: any;
9
+ accountMap: any;
10
+ profileMap: any;
11
+ }) => string;
@@ -1,3 +1,3 @@
1
- export declare const nextConfigTemplate: ({ keystonePath, }: {
2
- keystonePath: string;
3
- }) => string;
1
+ export declare const nextConfigTemplate: ({ keystonePath, }: {
2
+ keystonePath: string;
3
+ }) => string;
@@ -1,53 +1,45 @@
1
- import { BaseGeneratedListTypes, KeystoneConfig } from '@keystone-next/keystone/types';
2
- import { Provider } from 'next-auth/providers';
3
- export declare type AuthGqlNames = {
4
- CreateInitialInput: string;
5
- createInitialItem: string;
6
- authenticateItemWithPassword: string;
7
- ItemAuthenticationWithPasswordResult: string;
8
- ItemAuthenticationWithPasswordSuccess: string;
9
- ItemAuthenticationWithPasswordFailure: string;
10
- };
11
- export declare type NextAuthSession = {
12
- listKey: string;
13
- itemId: string;
14
- data: any;
15
- };
16
- export declare type NextAuthProviders = [Provider];
17
- declare type KeytoneAuthProviders = {
18
- providers: NextAuthProviders;
19
- };
20
- export declare type KeystoneAuthConfig = KeystoneConfig & KeytoneAuthProviders;
21
- export declare type AuthConfig<GeneratedListTypes extends BaseGeneratedListTypes> = {
22
- /** The key of the list to authenticate users with */
23
- listKey: GeneratedListTypes['key'];
24
- /** The path of the field the identity is stored in; must be text-ish */
25
- identityField: GeneratedListTypes['fields'];
26
- /** Session data population */
27
- sessionData?: string;
28
- /** Auth Create users in Keystone DB from Auth Provider */
29
- autoCreate: boolean;
30
- /** Map User in next-auth to item */
31
- userMap: any;
32
- /** Map Account in next-auth to item */
33
- accountMap: any;
34
- /** Map Profile in next-auth to item */
35
- profileMap: any;
36
- /** Path for Keystone interface */
37
- keystonePath?: string;
38
- /** Providers for Next Auth */
39
- providers: NextAuthProviders;
40
- };
41
- export declare type InitFirstItemConfig<GeneratedListTypes extends BaseGeneratedListTypes> = {
42
- /** Array of fields to collect, e.g ['name', 'email', 'password'] */
43
- fields: GeneratedListTypes['fields'][];
44
- /** Suppresses the second screen where we ask people to subscribe and follow Keystone */
45
- skipKeystoneWelcome?: boolean;
46
- /** Extra input to add for the create mutation */
47
- itemData?: Partial<GeneratedListTypes['inputs']['create']>;
48
- };
49
- export declare type AuthTokenRequestErrorCode = 'IDENTITY_NOT_FOUND' | 'MULTIPLE_IDENTITY_MATCHES';
50
- export declare type PasswordAuthErrorCode = AuthTokenRequestErrorCode | 'FAILURE' | 'SECRET_NOT_SET' | 'SECRET_MISMATCH';
51
- export declare type NextAuthErrorCode = AuthTokenRequestErrorCode | 'FAILURE' | 'SUBJECT_NOT_FOUND';
52
- export declare type AuthTokenRedemptionErrorCode = AuthTokenRequestErrorCode | 'FAILURE' | 'TOKEN_NOT_SET' | 'TOKEN_MISMATCH' | 'TOKEN_EXPIRED' | 'TOKEN_REDEEMED';
53
- export {};
1
+ import { BaseGeneratedListTypes, KeystoneConfig } from '@keystone-next/keystone/types';
2
+ import { Provider } from 'next-auth/providers';
3
+ export declare type AuthGqlNames = {
4
+ CreateInitialInput: string;
5
+ createInitialItem: string;
6
+ authenticateItemWithPassword: string;
7
+ ItemAuthenticationWithPasswordResult: string;
8
+ ItemAuthenticationWithPasswordSuccess: string;
9
+ ItemAuthenticationWithPasswordFailure: string;
10
+ };
11
+ export declare type NextAuthSession = {
12
+ listKey: string;
13
+ itemId: string;
14
+ data: any;
15
+ };
16
+ export declare type NextAuthProviders = [Provider];
17
+ declare type KeytoneAuthProviders = {
18
+ providers: NextAuthProviders;
19
+ };
20
+ export declare type KeystoneAuthConfig = KeystoneConfig & KeytoneAuthProviders;
21
+ export declare type AuthConfig<GeneratedListTypes extends BaseGeneratedListTypes> = {
22
+ /** The key of the list to authenticate users with */
23
+ listKey: GeneratedListTypes['key'];
24
+ /** The path of the field the identity is stored in; must be text-ish */
25
+ identityField: GeneratedListTypes['fields'];
26
+ /** Session data population */
27
+ sessionData?: string;
28
+ /** Auth Create users in Keystone DB from Auth Provider */
29
+ autoCreate: boolean;
30
+ /** Map User in next-auth to item */
31
+ userMap: any;
32
+ /** Map Account in next-auth to item */
33
+ accountMap: any;
34
+ /** Map Profile in next-auth to item */
35
+ profileMap: any;
36
+ /** Path for Keystone interface */
37
+ keystonePath?: string;
38
+ /** Providers for Next Auth */
39
+ providers: NextAuthProviders;
40
+ };
41
+ export declare type AuthTokenRequestErrorCode = 'IDENTITY_NOT_FOUND' | 'MULTIPLE_IDENTITY_MATCHES';
42
+ export declare type PasswordAuthErrorCode = AuthTokenRequestErrorCode | 'FAILURE' | 'SECRET_NOT_SET' | 'SECRET_MISMATCH';
43
+ export declare type NextAuthErrorCode = AuthTokenRequestErrorCode | 'FAILURE' | 'SUBJECT_NOT_FOUND';
44
+ export declare type AuthTokenRedemptionErrorCode = AuthTokenRequestErrorCode | 'FAILURE' | 'TOKEN_NOT_SET' | 'TOKEN_MISMATCH' | 'TOKEN_EXPIRED' | 'TOKEN_REDEEMED';
45
+ export {};
@@ -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: process.env.NODE_ENV === '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,