@opensaas/keystone-nextjs-auth 16.0.0 → 18.0.1

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.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 9b6052a: Fix access issue to allow `/api/__keystone_api_build`
8
+
9
+ ## 18.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - cff5031: Upgrade to `"@keystone-next/keystone": "^29.0.0"` see https://keystonejs.com/releases/2021-11-24 for more information
14
+
15
+ ## 17.0.0
16
+
17
+ ### Major Changes
18
+
19
+ - c619df8: Upgrade to `"@keystone-next/keystone": "28.0.0"`
20
+
21
+ ## 16.0.1
22
+
23
+ ### Patch Changes
24
+
25
+ - 2e3ae54: Fix Nullish coalescing operator in next-config for older versions of node
26
+
3
27
  ## 16.0.0
4
28
 
5
29
  ### Major Changes
@@ -78,7 +78,7 @@ module.exports = withPreconstruct({
78
78
  // to resolve the location of field views, we will get a path that we can use
79
79
  // rather than just the __dirname/__filename of the generated file.
80
80
  // https://webpack.js.org/configuration/node/#node__filename
81
- config.node ??= {};
81
+ (_config$node = config.node) !== null && _config$node !== void 0 ? _config$node : config.node = {};
82
82
  config.node.__dirname = true;
83
83
  config.node.__filename = true;
84
84
  }
@@ -267,6 +267,10 @@ function createAuth({
267
267
  } = context;
268
268
  const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
269
269
 
270
+ if (pathname === `${customPath}/api/__keystone_api_build`) {
271
+ return;
272
+ }
273
+
270
274
  if (isValidSession) {
271
275
  if (pathname === `${customPath}/api/auth/signin`) {
272
276
  return {
@@ -452,11 +456,15 @@ function createAuth({
452
456
  },
453
457
  enableSessionItem: true,
454
458
  isAccessAllowed: async context => {
455
- var _context$req, _keystoneConfig$ui3;
459
+ var _context$req, _context$req2, _keystoneConfig$ui3;
456
460
 
457
- // Allow access to the adminMeta data from the /init path to correctly render that page
461
+ 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`) {
462
+ return true;
463
+ } // Allow access to the adminMeta data from the /init path to correctly render that page
458
464
  // even if the user isn't logged in (which should always be the case if they're seeing /init)
459
- const headers = (_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.headers;
465
+
466
+
467
+ const headers = (_context$req2 = context.req) === null || _context$req2 === void 0 ? void 0 : _context$req2.headers;
460
468
  const host = headers ? headers['x-forwarded-host'] || headers.host : null;
461
469
  const thisUrl = headers !== null && headers !== void 0 && headers.referer ? new _URL__default["default"](headers.referer) : undefined;
462
470
  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;
@@ -78,7 +78,7 @@ module.exports = withPreconstruct({
78
78
  // to resolve the location of field views, we will get a path that we can use
79
79
  // rather than just the __dirname/__filename of the generated file.
80
80
  // https://webpack.js.org/configuration/node/#node__filename
81
- config.node ??= {};
81
+ (_config$node = config.node) !== null && _config$node !== void 0 ? _config$node : config.node = {};
82
82
  config.node.__dirname = true;
83
83
  config.node.__filename = true;
84
84
  }
@@ -267,6 +267,10 @@ function createAuth({
267
267
  } = context;
268
268
  const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
269
269
 
270
+ if (pathname === `${customPath}/api/__keystone_api_build`) {
271
+ return;
272
+ }
273
+
270
274
  if (isValidSession) {
271
275
  if (pathname === `${customPath}/api/auth/signin`) {
272
276
  return {
@@ -452,11 +456,11 @@ function createAuth({
452
456
  },
453
457
  enableSessionItem: true,
454
458
  isAccessAllowed: async context => {
455
- var _context$req, _keystoneConfig$ui3;
456
-
457
- // Allow access to the adminMeta data from the /init path to correctly render that page
459
+ var _context$req2, _keystoneConfig$ui3;
458
460
  // even if the user isn't logged in (which should always be the case if they're seeing /init)
459
- const headers = (_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.headers;
461
+
462
+
463
+ const headers = (_context$req2 = context.req) === null || _context$req2 === void 0 ? void 0 : _context$req2.headers;
460
464
  const host = headers ? headers['x-forwarded-host'] || headers.host : null;
461
465
  const thisUrl = headers !== null && headers !== void 0 && headers.referer ? new _URL__default["default"](headers.referer) : undefined;
462
466
  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;
@@ -44,7 +44,7 @@ module.exports = withPreconstruct({
44
44
  // to resolve the location of field views, we will get a path that we can use
45
45
  // rather than just the __dirname/__filename of the generated file.
46
46
  // https://webpack.js.org/configuration/node/#node__filename
47
- config.node ??= {};
47
+ (_config$node = config.node) !== null && _config$node !== void 0 ? _config$node : config.node = {};
48
48
  config.node.__dirname = true;
49
49
  config.node.__filename = true;
50
50
  }
@@ -233,6 +233,10 @@ function createAuth({
233
233
  } = context;
234
234
  const pathname = url.parse(req === null || req === void 0 ? void 0 : req.url).pathname;
235
235
 
236
+ if (pathname === `${customPath}/api/__keystone_api_build`) {
237
+ return;
238
+ }
239
+
236
240
  if (isValidSession) {
237
241
  if (pathname === `${customPath}/api/auth/signin`) {
238
242
  return {
@@ -418,11 +422,15 @@ function createAuth({
418
422
  },
419
423
  enableSessionItem: true,
420
424
  isAccessAllowed: async context => {
421
- var _context$req, _keystoneConfig$ui3;
425
+ var _context$req, _context$req2, _keystoneConfig$ui3;
422
426
 
423
- // Allow access to the adminMeta data from the /init path to correctly render that page
427
+ 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`) {
428
+ return true;
429
+ } // Allow access to the adminMeta data from the /init path to correctly render that page
424
430
  // even if the user isn't logged in (which should always be the case if they're seeing /init)
425
- const headers = (_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.headers;
431
+
432
+
433
+ const headers = (_context$req2 = context.req) === null || _context$req2 === void 0 ? void 0 : _context$req2.headers;
426
434
  const host = headers ? headers['x-forwarded-host'] || headers.host : null;
427
435
  const thisUrl = headers !== null && headers !== void 0 && headers.referer ? new _URL(headers.referer) : undefined;
428
436
  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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opensaas/keystone-nextjs-auth",
3
- "version": "16.0.0",
3
+ "version": "18.0.1",
4
4
  "repository": "https://github.com/opensaasau/keystone-nextjs-auth",
5
5
  "license": "MIT",
6
6
  "main": "dist/opensaas-keystone-nextjs-auth.cjs.js",
@@ -9,7 +9,7 @@
9
9
  "@babel/runtime": "^7.15.8",
10
10
  "@babel/runtime-corejs3": "^7.15.4",
11
11
  "@keystone-next/admin-ui-utils": "^6.0.0",
12
- "@types/ejs": "^3.0.6",
12
+ "@types/ejs": "^3.1.0",
13
13
  "cookie": "^0.4.1",
14
14
  "cross-fetch": "^3.1.4",
15
15
  "ejs": "^3.1.6",
@@ -18,11 +18,11 @@
18
18
  "next-auth": "^3.29.0"
19
19
  },
20
20
  "devDependencies": {
21
- "@keystone-next/keystone": "^27.0.1",
21
+ "@keystone-next/keystone": "^29.0.0",
22
22
  "react": "^17.0.2"
23
23
  },
24
24
  "peerDependencies": {
25
- "@keystone-next/keystone": "^27.0.1",
25
+ "@keystone-next/keystone": "^29.0.0",
26
26
  "react": "^17.0.2"
27
27
  },
28
28
  "engines": {
package/src/index.ts CHANGED
@@ -73,7 +73,9 @@ export function createAuth<GeneratedListTypes extends BaseGeneratedListTypes>({
73
73
  }) => {
74
74
  const { req, session } = context;
75
75
  const pathname = url.parse(req?.url!).pathname!;
76
-
76
+ if (pathname === `${customPath}/api/__keystone_api_build`) {
77
+ return;
78
+ }
77
79
  if (isValidSession) {
78
80
  if (pathname === `${customPath}/api/auth/signin`) {
79
81
  return { kind: 'redirect', to: `${customPath}` };
@@ -244,6 +246,14 @@ export function createAuth<GeneratedListTypes extends BaseGeneratedListTypes>({
244
246
  keystoneConfig?.ui?.pageMiddleware?.(args),
245
247
  enableSessionItem: true,
246
248
  isAccessAllowed: async (context: KeystoneContext) => {
249
+ if (
250
+ process.env.NODE_ENV !== 'production' &&
251
+ context.req?.url !== undefined &&
252
+ new URL(context.req.url, 'http://example.com').pathname ===
253
+ `${customPath}/api/__keystone_api_build`
254
+ ) {
255
+ return true;
256
+ }
247
257
  // Allow access to the adminMeta data from the /init path to correctly render that page
248
258
  // even if the user isn't logged in (which should always be the case if they're seeing /init)
249
259
  const headers = context.req?.headers;
@@ -31,7 +31,7 @@ module.exports = withPreconstruct({
31
31
  // to resolve the location of field views, we will get a path that we can use
32
32
  // rather than just the __dirname/__filename of the generated file.
33
33
  // https://webpack.js.org/configuration/node/#node__filename
34
- config.node ??= {};
34
+ (_config$node = config.node) !== null && _config$node !== void 0 ? _config$node : config.node = {};
35
35
  config.node.__dirname = true;
36
36
  config.node.__filename = true;
37
37
  }