@opensaas/keystone-nextjs-auth 25.0.0-rc-1 → 26.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @opensaas-keystone/nextjs-auth
2
2
 
3
+ ## 26.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - fac7086: Upgrade to `keystone-6/core@4.0.0`
8
+
9
+ ### Minor Changes
10
+
11
+ - ed67215: Update dependency next-auth to ^4.17.0
12
+ - 9643191: Upgrade next-auth and fix types
13
+ - b9dbb77: Upgrade to keystone `3.1.0`
14
+
15
+ ### Patch Changes
16
+
17
+ - b9dbb77: Resolve error when `isAccessAllowed` is not defined
18
+ - 5b0af33: Simplify NextJS config of Keystone path and resolve redirect loops
19
+
20
+ ## 25.0.0
21
+
22
+ ### Major Changes
23
+
24
+ - a759195: Upgrade to keystone-6@3.0.0
25
+
26
+ ### Minor Changes
27
+
28
+ - 44031fa: Update `next-auth` to `4.14`
29
+
3
30
  ## 24.1.0
4
31
 
5
32
  ### Minor Changes
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Keystone next auth
2
+
2
3
  This package enables the addition of social auth to keystone-6.
3
4
 
4
5
  ## Contents
@@ -9,6 +10,7 @@ This package enables the addition of social auth to keystone-6.
9
10
  - [Contributing](#contributing)
10
11
 
11
12
  ## About
13
+
12
14
  This uses NextAuth.js (https://next-auth.js.org/) project to add social auth to Keystone-6 (https://keystonejs.com/). Primary testing has been done with Auth0, happy for others to test other providers/give feedback or send through a PR.
13
15
 
14
16
  ## Adding to your project
@@ -20,7 +22,6 @@ Add import...
20
22
  ```javascript
21
23
  import { createAuth } from '@opensaas/keystone-nextjs-auth';
22
24
  import Auth0 from '@opensaas/keystone-nextjs-auth/providers/auth0';
23
-
24
25
  ```
25
26
 
26
27
  Add you Auth configuration including providers
@@ -60,7 +61,8 @@ const auth = createAuth({
60
61
  ]
61
62
  });
62
63
  ```
63
- Wrap your keystone config in `auth.withAuth`. Note that `generateNodeAPI` is required.
64
+
65
+ Wrap your keystone config in `auth.withAuth`.
64
66
 
65
67
  ```javascript
66
68
  export default auth.withAuth(
@@ -69,32 +71,32 @@ export default auth.withAuth(
69
71
  db: {},
70
72
  ui: {},
71
73
  lists,
72
- experimental: {
73
- generateNodeAPI: true,
74
- },
75
74
  ...
76
75
  });
77
76
  ```
78
77
 
79
78
  ## Configuration
79
+
80
80
  Provider configuration see https://next-auth.js.org/configuration/providers.
81
81
  For Keystone-6 Configuration see https://keystonejs.com/
82
82
  for example see the example [backend](./backend)
83
83
 
84
- - listKey - the list for authentication (generally `'User'`). Make sure any required fields are set using the `*Map` fields, see note below.
85
- - identityField - The field that stores the identity/subjectId in keystone (generally `'subjectId'`). You will need to add this field to your list schema specified by `listKey`. An example can be found [here](./backend/schemas/User.ts).
86
- - sessionData - Data to be stored in the session ( something like `'id name email'`),
87
- - autoCreate - boolean to autocreate a user when they log in
88
- - userMap: `key:value` pairs that define what is copied from the User object returned from NextAuth in the SignIn callback (https://next-auth.js.org/configuration/callbacks#sign-in-callback) Left side is Keystone side, right is what comes from NextAuth eg: `{ subjectId: 'id', name: 'name' }`
89
- - accountMap - As Above but for the Account object
90
- - profileMap - As Above but for the Profile object
91
- - keystonePath - the path you want to access keystone from your frontend app (if required).
84
+ - listKey - the list for authentication (generally `'User'`). Make sure any required fields are set using the `*Map` fields, see note below.
85
+ - identityField - The field that stores the identity/subjectId in keystone (generally `'subjectId'`). You will need to add this field to your list schema specified by `listKey`. An example can be found [here](./backend/schemas/User.ts).
86
+ - sessionData - Data to be stored in the session ( something like `'id name email'`),
87
+ - autoCreate - boolean to autocreate a user when they log in
88
+ - userMap: `key:value` pairs that define what is copied from the User object returned from NextAuth in the SignIn callback (https://next-auth.js.org/configuration/callbacks#sign-in-callback) Left side is Keystone side, right is what comes from NextAuth eg: `{ subjectId: 'id', name: 'name' }`
89
+ - accountMap - As Above but for the Account object
90
+ - profileMap - As Above but for the Profile object
91
+ - keystonePath - the path you want to access keystone from your frontend app (if required).
92
92
 
93
93
  Note: The Keystone `create-keystone-app` CLI app (generally run with `yarn create keystone-app`/`npm init keystone-app`) will set a required `password` field on the `User` list. If you've used this to set up your project you will need to modify your list schema to set the field as not required, or remove it entirely if you don't plan to use the default Keystone auth system at all.
94
94
 
95
95
  ## Contributing
96
+
96
97
  If you want to run this package locally
97
98
  After cloning run `yarn install` and either:
99
+
98
100
  - `yarn dev` to run both the frontend and backend or
99
101
  - `yarn dev:backend` for just the backend
100
102
 
@@ -2,14 +2,14 @@ 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
- export declare type NextAuthTemplateProps = {
5
+ export type NextAuthTemplateProps = {
6
6
  autoCreate: boolean;
7
7
  identityField: string;
8
8
  listKey: string;
9
9
  sessionData: string | undefined;
10
10
  sessionSecret: string;
11
11
  };
12
- export declare type CoreNextAuthPageProps = {
12
+ export type CoreNextAuthPageProps = {
13
13
  cookies?: Partial<CookiesOptions>;
14
14
  events?: Partial<EventCallbacks>;
15
15
  jwt?: Partial<JWTOptions>;
@@ -23,7 +23,7 @@ export declare type CoreNextAuthPageProps = {
23
23
  [key: string]: boolean | string | number;
24
24
  }>;
25
25
  } & NextAuthTemplateProps;
26
- export declare type NextAuthPageProps = CoreNextAuthPageProps & {
26
+ export type NextAuthPageProps = CoreNextAuthPageProps & {
27
27
  query: KeystoneListsAPI<any>;
28
28
  };
29
29
  export default function NextAuthPage(props: NextAuthPageProps): any;
@@ -1,37 +1,29 @@
1
- /// <reference types="node" />
2
- import type { ServerResponse, IncomingMessage } from 'http';
3
- import type { NextRequest } from 'next/server';
4
1
  import { Provider } from 'next-auth/providers';
5
2
  import { CookiesOptions, PagesOptions } from 'next-auth';
6
- import { BaseListTypeInfo, KeystoneConfig, CreateContext } from '@keystone-6/core/types';
7
- declare type NextAuthResponse = IncomingMessage & NextRequest;
3
+ import { BaseListTypeInfo, KeystoneConfig, KeystoneContext } from '@keystone-6/core/types';
8
4
  export declare type AuthSessionStrategy<StoredSessionData> = {
9
5
  start: (args: {
10
- res: ServerResponse;
11
6
  data: any;
12
- createContext: CreateContext;
13
- }) => Promise<string>;
7
+ context: KeystoneContext;
8
+ }) => Promise<unknown>;
14
9
  end: (args: {
15
- req: IncomingMessage;
16
- res: ServerResponse;
17
- createContext: CreateContext;
18
- }) => Promise<void>;
10
+ context: KeystoneContext;
11
+ }) => Promise<unknown>;
19
12
  get: (args: {
20
- req: NextAuthResponse;
21
- createContext: CreateContext;
13
+ context: KeystoneContext;
22
14
  }) => Promise<StoredSessionData | undefined>;
23
15
  };
24
- export declare type NextAuthProviders = Provider[];
25
- declare type KeytoneOAuthOptions = {
16
+ export type NextAuthProviders = Provider[];
17
+ type KeytoneOAuthOptions = {
26
18
  providers: NextAuthProviders;
27
19
  pages?: Partial<PagesOptions>;
28
20
  };
29
- declare type NextAuthOptions = {
21
+ type NextAuthOptions = {
30
22
  cookies?: Partial<CookiesOptions>;
31
23
  resolver: any;
32
24
  };
33
- export declare type KeystoneOAuthConfig = KeystoneConfig & KeytoneOAuthOptions & NextAuthOptions;
34
- export declare type AuthConfig<GeneratedListTypes extends BaseListTypeInfo> = {
25
+ export type KeystoneOAuthConfig = KeystoneConfig & KeytoneOAuthOptions & NextAuthOptions;
26
+ export type AuthConfig<GeneratedListTypes extends BaseListTypeInfo> = {
35
27
  /** Auth Create users in Keystone DB from Auth Provider */
36
28
  autoCreate: boolean;
37
29
  /** Adds ability to customize cookie options, for example, to facilitate cross-subdomain functionality */
@@ -58,8 +50,8 @@ export declare type AuthConfig<GeneratedListTypes extends BaseListTypeInfo> = {
58
50
  /** Next-Auth Session Secret */
59
51
  sessionSecret: string;
60
52
  };
61
- export declare type AuthTokenRequestErrorCode = 'IDENTITY_NOT_FOUND' | 'MULTIPLE_IDENTITY_MATCHES';
62
- export declare type PasswordAuthErrorCode = AuthTokenRequestErrorCode | 'FAILURE' | 'SECRET_NOT_SET' | 'SECRET_MISMATCH';
63
- export declare type NextAuthErrorCode = AuthTokenRequestErrorCode | 'FAILURE' | 'SUBJECT_NOT_FOUND';
64
- export declare type AuthTokenRedemptionErrorCode = AuthTokenRequestErrorCode | 'FAILURE' | 'TOKEN_NOT_SET' | 'TOKEN_MISMATCH' | 'TOKEN_EXPIRED' | 'TOKEN_REDEEMED';
53
+ export type AuthTokenRequestErrorCode = 'IDENTITY_NOT_FOUND' | 'MULTIPLE_IDENTITY_MATCHES';
54
+ export type PasswordAuthErrorCode = AuthTokenRequestErrorCode | 'FAILURE' | 'SECRET_NOT_SET' | 'SECRET_MISMATCH';
55
+ export type NextAuthErrorCode = AuthTokenRequestErrorCode | 'FAILURE' | 'SUBJECT_NOT_FOUND';
56
+ export type AuthTokenRedemptionErrorCode = AuthTokenRequestErrorCode | 'FAILURE' | 'TOKEN_NOT_SET' | 'TOKEN_MISMATCH' | 'TOKEN_EXPIRED' | 'TOKEN_REDEEMED';
65
57
  export {};
@@ -7,7 +7,7 @@ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProp
7
7
  var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
8
8
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
9
9
  var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
10
- var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
10
+ var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
11
11
  var url = require('url');
12
12
  var react = require('next-auth/react');
13
13
  var jwt = require('next-auth/jwt');
@@ -39,68 +39,19 @@ function _interopNamespace(e) {
39
39
  var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
40
40
  var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
41
41
  var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
42
- var _URL__default = /*#__PURE__*/_interopDefault(_URL);
42
+ var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
43
43
  var url__default = /*#__PURE__*/_interopDefault(url);
44
44
  var cookie__namespace = /*#__PURE__*/_interopNamespace(cookie);
45
45
  var ejs__default = /*#__PURE__*/_interopDefault(ejs);
46
46
  var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
47
47
 
48
48
  const template$1 = `
49
- const Path = require('path');
50
- // @ts-ignore
51
- const withPreconstruct = require('@preconstruct/next');
52
-
53
- module.exports = withPreconstruct({
54
- typescript: {
55
- ignoreBuildErrors: true,
56
- },
57
- env: {
58
- NEXTAUTH_URL: process.env.NEXTAUTH_URL || 'http://localhost:<%= process.env.PORT || 3000 %><%= keystonePath || '' %>/api/auth',
59
- },
60
- eslint: {
61
- ignoreDuringBuilds: true,
62
- },
63
- webpack(config, { isServer }) {
64
- config.resolve.alias = {
65
- ...config.resolve.alias,
66
- react: Path.dirname(require.resolve('react/package.json')),
67
- 'react-dom': Path.dirname(require.resolve('react-dom/package.json')),
68
- '@keystone-6/core': Path.dirname(
69
- require.resolve('@keystone-6/core/package.json')
70
- ),
71
- };
72
- if (isServer) {
73
- config.externals = [
74
- ...config.externals,
75
- /@keystone-6\\/core(?!\\/___internal-do-not-use-will-break-in-patch\\/admin-ui\\/id-field-view|\\/fields\\/types\\/[^\\/]+\\/views)/,
76
- /.prisma\\/client/
77
- ];
78
- // we need to set these to true so that when __dirname/__filename is used
79
- // to resolve the location of field views, we will get a path that we can use
80
- // rather than just the __dirname/__filename of the generated file.
81
- // https://webpack.js.org/configuration/node/#node__filename
82
- (_config$node = config.node) !== null && _config$node !== void 0 ? _config$node : config.node = {};
83
- config.node.__dirname = true;
84
- config.node.__filename = true;
85
- }
86
- return config;
87
- },
88
- <% if (keystonePath) { %>
89
- <% if (process.env.NODE_ENV != 'production') { %>
90
- async rewrites() {
91
- return [
92
- {
93
- source: '/api/__keystone_api_build',
94
- destination: 'http://localhost:<%= process.env.PORT || 3000 %><%= keystonePath || '' %>/api/__keystone_api_build',
95
- basePath: false
96
- }
97
- ];
98
- },
99
- <% }%>
100
- basePath: '<%= keystonePath || '' %>'
101
- <% } %>
102
- });
103
- `;
49
+ const keystoneConfig = require('@keystone-6/core/___internal-do-not-use-will-break-in-patch/admin-ui/next-config').config;
50
+
51
+ module.exports = {
52
+ ...keystoneConfig,
53
+ basePath: '<%= keystonePath || '' %>'
54
+ };`;
104
55
  const nextConfigTemplate = _ref => {
105
56
  let {
106
57
  keystonePath
@@ -245,7 +196,7 @@ function createAuth(_ref) {
245
196
  * - to the signin page when no valid session is present
246
197
  */
247
198
 
248
- const pageMiddleware = async _ref2 => {
199
+ const authMiddleware = async _ref2 => {
249
200
  let {
250
201
  context,
251
202
  isValidSession
@@ -257,13 +208,6 @@ function createAuth(_ref) {
257
208
  const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
258
209
 
259
210
  if (isValidSession) {
260
- if (pathname === `${customPath}/api/auth/signin` || pages !== null && pages !== void 0 && pages.signIn && _includesInstanceProperty__default["default"](pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.signIn)) {
261
- return {
262
- kind: 'redirect',
263
- to: `${customPath}`
264
- };
265
- }
266
-
267
211
  if (customPath !== '' && pathname === '/') {
268
212
  return {
269
213
  kind: 'redirect',
@@ -274,10 +218,6 @@ function createAuth(_ref) {
274
218
  return;
275
219
  }
276
220
 
277
- if (_includesInstanceProperty__default["default"](pathname).call(pathname, '/_next/') || _includesInstanceProperty__default["default"](pathname).call(pathname, '/api/auth/') || pages !== null && pages !== void 0 && pages.signIn && _includesInstanceProperty__default["default"](pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.signIn) || pages !== null && pages !== void 0 && pages.error && _includesInstanceProperty__default["default"](pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.error) || pages !== null && pages !== void 0 && pages.signOut && _includesInstanceProperty__default["default"](pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.signOut)) {
278
- return;
279
- }
280
-
281
221
  if (!session && !_includesInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/api/auth/`)) {
282
222
  return {
283
223
  kind: 'redirect',
@@ -286,7 +226,7 @@ function createAuth(_ref) {
286
226
  }
287
227
  };
288
228
  /**
289
- * getAdditionalFiles
229
+ * authGetAdditionalFiles
290
230
  *
291
231
  * This function adds files to be generated into the Admin UI build. Must be added to the
292
232
  * ui.getAdditionalFiles config.
@@ -295,7 +235,7 @@ function createAuth(_ref) {
295
235
  */
296
236
 
297
237
 
298
- const getAdditionalFiles = () => {
238
+ const authGetAdditionalFiles = () => {
299
239
  const filesToWrite = [{
300
240
  mode: 'write',
301
241
  outputPath: 'pages/api/auth/[...nextauth].js',
@@ -322,13 +262,13 @@ function createAuth(_ref) {
322
262
  */
323
263
 
324
264
 
325
- 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
265
+ const authPublicPages = [`${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
326
266
  // @ts-ignore
327
267
 
328
268
  function addPages(provider) {
329
269
  const name = provider.id;
330
- publicPages.push(`${customPath}/api/auth/signin/${name}`);
331
- publicPages.push(`${customPath}/api/auth/callback/${name}`);
270
+ authPublicPages.push(`${customPath}/api/auth/signin/${name}`);
271
+ authPublicPages.push(`${customPath}/api/auth/callback/${name}`);
332
272
  }
333
273
 
334
274
  _mapInstanceProperty__default["default"](providers).call(providers, addPages);
@@ -394,23 +334,24 @@ function createAuth(_ref) {
394
334
  var _req$headers, _req$headers$authoriz;
395
335
 
396
336
  let {
397
- req,
398
- createContext
337
+ context
399
338
  } = _ref3;
339
+ const {
340
+ req
341
+ } = context;
400
342
  const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
401
343
  let nextSession;
344
+ if (!req) return;
402
345
 
403
346
  if (_includesInstanceProperty__default["default"](pathname).call(pathname, '/api/auth')) {
404
347
  return;
405
348
  }
406
349
 
407
- const sudoContext = createContext({
408
- sudo: true
409
- });
350
+ const sudoContext = context.sudo();
410
351
 
411
352
  if (((_req$headers = req.headers) === null || _req$headers === void 0 ? void 0 : (_req$headers$authoriz = _req$headers.authorization) === null || _req$headers$authoriz === void 0 ? void 0 : _req$headers$authoriz.split(' ')[0]) === 'Bearer') {
412
353
  nextSession = await jwt.getToken({
413
- req,
354
+ req: req,
414
355
  secret: sessionSecret
415
356
  });
416
357
  } else {
@@ -430,8 +371,7 @@ function createAuth(_ref) {
430
371
  data: nextSession.data
431
372
  };
432
373
  const userSession = await get({
433
- req: reqWithUser,
434
- createContext
374
+ context
435
375
  });
436
376
  return _objectSpread(_objectSpread(_objectSpread({}, userSession), nextSession), {}, {
437
377
  data: nextSession.data,
@@ -441,16 +381,17 @@ function createAuth(_ref) {
441
381
  },
442
382
  end: async _ref4 => {
443
383
  let {
444
- res,
445
- req,
446
- createContext
384
+ context
447
385
  } = _ref4;
448
386
  await end({
449
- res,
450
- req,
451
- createContext
387
+ context
452
388
  });
453
389
  const TOKEN_NAME = process.env.NODE_ENV === 'production' ? '__Secure-next-auth.session-token' : 'next-auth.session-token';
390
+ const {
391
+ req,
392
+ res
393
+ } = context;
394
+ if (!req || !res) return;
454
395
  res.setHeader('Set-Cookie', cookie__namespace.serialize(TOKEN_NAME, '', {
455
396
  maxAge: 0,
456
397
  expires: new Date(),
@@ -464,6 +405,13 @@ function createAuth(_ref) {
464
405
  }
465
406
  });
466
407
  };
408
+
409
+ function defaultIsAccessAllowed(_ref5) {
410
+ let {
411
+ session
412
+ } = _ref5;
413
+ return session !== undefined;
414
+ }
467
415
  /**
468
416
  * withAuth
469
417
  *
@@ -477,40 +425,38 @@ function createAuth(_ref) {
477
425
 
478
426
 
479
427
  const withAuth = keystoneConfig => {
428
+ var _ui;
429
+
480
430
  validateConfig(keystoneConfig);
481
431
  let {
482
432
  ui
483
433
  } = keystoneConfig;
484
434
 
485
- if (keystoneConfig.ui) {
486
- var _keystoneConfig$ui;
487
-
488
- ui = _objectSpread(_objectSpread({}, keystoneConfig.ui), {}, {
489
- publicPages: [...(keystoneConfig.ui.publicPages || []), ...publicPages],
490
- getAdditionalFiles: [...(((_keystoneConfig$ui = keystoneConfig.ui) === null || _keystoneConfig$ui === void 0 ? void 0 : _keystoneConfig$ui.getAdditionalFiles) || []), getAdditionalFiles],
491
- pageMiddleware: async args => {
492
- var _keystoneConfig$ui2, _keystoneConfig$ui2$p;
493
-
494
- return (await pageMiddleware(args)) ?? (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));
495
- },
435
+ if (!((_ui = ui) !== null && _ui !== void 0 && _ui.isDisabled)) {
436
+ const {
437
+ getAdditionalFiles = [],
438
+ isAccessAllowed = defaultIsAccessAllowed,
439
+ pageMiddleware,
440
+ publicPages = []
441
+ } = ui || {};
442
+ ui = _objectSpread(_objectSpread({}, ui), {}, {
443
+ publicPages: [...publicPages, ...authPublicPages],
496
444
  isAccessAllowed: async context => {
497
- var _context$req, _keystoneConfig$ui3;
498
-
499
- const {
500
- req
501
- } = context;
502
- const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname; // Allow nextjs scripts and static files to be accessed without auth
503
-
504
- if (_includesInstanceProperty__default["default"](pathname).call(pathname, '/_next/')) {
505
- return true;
506
- } // Allow keystone to access /api/__keystone_api_build for hot reloading
445
+ var _context$req;
507
446
 
447
+ const pathname = url__default["default"].parse((_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.url).pathname;
508
448
 
509
- if (process.env.NODE_ENV !== 'production' && ((_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.url) !== undefined && new _URL__default["default"](context.req.url, 'http://example.com').pathname === `${customPath}/api/__keystone_api_build`) {
449
+ if (_startsWithInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/_next`) || _startsWithInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/__next`) || _startsWithInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/api/auth/`) || pages !== null && pages !== void 0 && pages.signIn && _includesInstanceProperty__default["default"](pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.signIn) || pages !== null && pages !== void 0 && pages.error && _includesInstanceProperty__default["default"](pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.error) || pages !== null && pages !== void 0 && pages.signOut && _includesInstanceProperty__default["default"](pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.signOut)) {
510
450
  return true;
511
451
  }
512
452
 
513
- return (_keystoneConfig$ui3 = keystoneConfig.ui) !== null && _keystoneConfig$ui3 !== void 0 && _keystoneConfig$ui3.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined;
453
+ return await isAccessAllowed(context);
454
+ },
455
+ getAdditionalFiles: [...getAdditionalFiles, authGetAdditionalFiles],
456
+ pageMiddleware: async args => {
457
+ const shouldRedirect = await authMiddleware(args);
458
+ if (shouldRedirect) return shouldRedirect;
459
+ return pageMiddleware === null || pageMiddleware === void 0 ? void 0 : pageMiddleware(args);
514
460
  }
515
461
  });
516
462
  }