@opensaas/keystone-nextjs-auth 21.1.0 → 22.1.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 +22 -0
- package/dist/declarations/src/pages/NextAuthPage.d.ts +7 -1
- package/dist/declarations/src/templates/next-config.d.ts +1 -1
- package/dist/declarations/src/{types.d.ts → types/index.d.ts} +29 -8
- package/dist/opensaas-keystone-nextjs-auth.cjs.dev.js +28 -39
- package/dist/opensaas-keystone-nextjs-auth.cjs.prod.js +28 -39
- package/dist/opensaas-keystone-nextjs-auth.esm.js +28 -37
- package/package.json +2 -4
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.dev.js +51 -34
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.prod.js +51 -34
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.esm.js +51 -33
- package/src/gql/getBaseAuthSchema.ts +1 -4
- package/src/index.ts +68 -53
- package/src/lib/findMatchingIdentity.ts +1 -4
- package/src/pages/NextAuthPage.tsx +50 -57
- package/src/schema.ts +2 -4
- package/src/templates/next-config.ts +1 -5
- package/src/{types.ts → types/index.ts} +28 -11
- package/src/types/next-auth.d.ts +19 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
# @opensaas-keystone/nextjs-auth
|
2
2
|
|
3
|
+
## 22.1.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- b89f4e7: Invalidate user when deleted from database
|
8
|
+
|
9
|
+
### Patch Changes
|
10
|
+
|
11
|
+
- b89f4e7: signin pages error fix
|
12
|
+
|
13
|
+
## 22.0.0
|
14
|
+
|
15
|
+
### Major Changes
|
16
|
+
|
17
|
+
- 059d0cc: type fixes and and update user on login
|
18
|
+
|
19
|
+
## 21.1.1
|
20
|
+
|
21
|
+
### Patch Changes
|
22
|
+
|
23
|
+
- e48cb6c: Fix signin redirect error
|
24
|
+
|
3
25
|
## 21.1.0
|
4
26
|
|
5
27
|
### Minor Changes
|
@@ -11,7 +11,13 @@ declare type CoreNextAuthPageProps = {
|
|
11
11
|
listKey: string;
|
12
12
|
pages?: Partial<PagesOptions>;
|
13
13
|
providers?: Provider[];
|
14
|
-
resolver?:
|
14
|
+
resolver?: (args: {
|
15
|
+
user: any;
|
16
|
+
profile: any;
|
17
|
+
account: any;
|
18
|
+
}) => {
|
19
|
+
[key: string]: boolean | string | number;
|
20
|
+
};
|
15
21
|
sessionData: string | undefined;
|
16
22
|
sessionSecret: string;
|
17
23
|
};
|
@@ -1,10 +1,25 @@
|
|
1
|
-
|
2
|
-
import {
|
1
|
+
/// <reference types="node" />
|
2
|
+
import type { ServerResponse, IncomingMessage } from 'http';
|
3
|
+
import type { NextRequest } from 'next/server';
|
3
4
|
import { Provider } from 'next-auth/providers';
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
import { CookiesOptions, PagesOptions } from 'next-auth';
|
6
|
+
import { BaseListTypeInfo, KeystoneConfig, CreateContext } from '@keystone-6/core/types';
|
7
|
+
declare type NextAuthResponse = IncomingMessage & NextRequest;
|
8
|
+
export declare type AuthSessionStrategy<StoredSessionData> = {
|
9
|
+
start: (args: {
|
10
|
+
res: ServerResponse;
|
11
|
+
data: any;
|
12
|
+
createContext: CreateContext;
|
13
|
+
}) => Promise<string>;
|
14
|
+
end: (args: {
|
15
|
+
req: IncomingMessage;
|
16
|
+
res: ServerResponse;
|
17
|
+
createContext: CreateContext;
|
18
|
+
}) => Promise<void>;
|
19
|
+
get: (args: {
|
20
|
+
req: NextAuthResponse;
|
21
|
+
createContext: CreateContext;
|
22
|
+
}) => Promise<StoredSessionData | undefined>;
|
8
23
|
};
|
9
24
|
export declare type NextAuthProviders = Provider[];
|
10
25
|
declare type KeytoneOAuthOptions = {
|
@@ -27,11 +42,17 @@ export declare type AuthConfig<GeneratedListTypes extends BaseListTypeInfo> = {
|
|
27
42
|
identityField: GeneratedListTypes['fields'];
|
28
43
|
/** Path for Keystone interface */
|
29
44
|
keystonePath?: string;
|
30
|
-
pages?:
|
45
|
+
pages?: Partial<PagesOptions>;
|
31
46
|
/** Providers for Next Auth */
|
32
47
|
providers: NextAuthProviders;
|
33
48
|
/** Resolver for user to define their profile */
|
34
|
-
resolver?:
|
49
|
+
resolver?: (args: {
|
50
|
+
user: any;
|
51
|
+
profile: any;
|
52
|
+
account: any;
|
53
|
+
}) => Promise<{
|
54
|
+
[key: string]: boolean | string | number;
|
55
|
+
}>;
|
35
56
|
/** Session data population */
|
36
57
|
sessionData?: string | undefined;
|
37
58
|
/** Next-Auth Session Secret */
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
6
6
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
7
7
|
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
8
|
-
var _indexOfInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/index-of');
|
9
|
-
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
10
8
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
11
9
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
12
10
|
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
@@ -39,8 +37,6 @@ function _interopNamespace(e) {
|
|
39
37
|
}
|
40
38
|
|
41
39
|
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
42
|
-
var _indexOfInstanceProperty__default = /*#__PURE__*/_interopDefault(_indexOfInstanceProperty);
|
43
|
-
var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
|
44
40
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
45
41
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
46
42
|
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
@@ -200,7 +196,7 @@ const authTemplate = ({
|
|
200
196
|
return authOut;
|
201
197
|
};
|
202
198
|
|
203
|
-
const _excluded = ["get"
|
199
|
+
const _excluded = ["get"];
|
204
200
|
/**
|
205
201
|
* createAuth function
|
206
202
|
*
|
@@ -239,8 +235,6 @@ function createAuth({
|
|
239
235
|
context,
|
240
236
|
isValidSession
|
241
237
|
}) => {
|
242
|
-
var _context;
|
243
|
-
|
244
238
|
const {
|
245
239
|
req,
|
246
240
|
session
|
@@ -248,7 +242,7 @@ function createAuth({
|
|
248
242
|
const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
249
243
|
|
250
244
|
if (isValidSession) {
|
251
|
-
if (pathname === `${customPath}/api/auth/signin`) {
|
245
|
+
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)) {
|
252
246
|
return {
|
253
247
|
kind: 'redirect',
|
254
248
|
to: `${customPath}`
|
@@ -265,14 +259,14 @@ function createAuth({
|
|
265
259
|
return;
|
266
260
|
}
|
267
261
|
|
268
|
-
if (_includesInstanceProperty__default["default"](pathname).call(pathname, '/_next/') || _includesInstanceProperty__default["default"](pathname).call(pathname, '/api/auth/')) {
|
262
|
+
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)) {
|
269
263
|
return;
|
270
264
|
}
|
271
265
|
|
272
|
-
if (!session && !_includesInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/api/auth/`)
|
266
|
+
if (!session && !_includesInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/api/auth/`)) {
|
273
267
|
return {
|
274
268
|
kind: 'redirect',
|
275
|
-
to: `${customPath}/api/auth/signin`
|
269
|
+
to: (pages === null || pages === void 0 ? void 0 : pages.signIn) || `${customPath}/api/auth/signin`
|
276
270
|
};
|
277
271
|
}
|
278
272
|
};
|
@@ -374,53 +368,48 @@ function createAuth({
|
|
374
368
|
|
375
369
|
|
376
370
|
const withItemData = _sessionStrategy => {
|
377
|
-
const
|
378
|
-
get,
|
379
|
-
start
|
380
|
-
} = _sessionStrategy,
|
381
|
-
sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
|
371
|
+
const sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
|
382
372
|
|
383
373
|
return _objectSpread(_objectSpread({}, sessionStrategy), {}, {
|
384
|
-
start: async ({
|
385
|
-
|
386
|
-
}) => {
|
387
|
-
console.log('start');
|
388
|
-
const session = await start({
|
389
|
-
res
|
390
|
-
});
|
391
|
-
return session;
|
374
|
+
start: async () => {
|
375
|
+
return 'false';
|
392
376
|
},
|
393
377
|
get: async ({
|
394
|
-
req
|
378
|
+
req,
|
379
|
+
createContext
|
395
380
|
}) => {
|
396
|
-
var _req$headers$authoriz;
|
381
|
+
var _req$headers, _req$headers$authoriz;
|
397
382
|
|
383
|
+
const sudoContext = createContext({
|
384
|
+
sudo: true
|
385
|
+
});
|
398
386
|
const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
387
|
+
let nextSession;
|
399
388
|
|
400
389
|
if (_includesInstanceProperty__default["default"](pathname).call(pathname, '/api/auth')) {
|
401
390
|
return;
|
402
391
|
}
|
403
392
|
|
404
|
-
if (((_req$headers
|
405
|
-
|
406
|
-
|
407
|
-
const token = await jwt.getToken({
|
393
|
+
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') {
|
394
|
+
nextSession = await jwt.getToken({
|
408
395
|
req,
|
409
396
|
secret: sessionSecret
|
410
397
|
});
|
398
|
+
} else {
|
399
|
+
nextSession = await react.getSession({
|
400
|
+
req
|
401
|
+
});
|
402
|
+
}
|
411
403
|
|
412
|
-
|
413
|
-
|
414
|
-
}
|
404
|
+
if (!nextSession || !nextSession.listKey || nextSession.listKey !== listKey || !nextSession.itemId || !sudoContext.query[listKey] || !nextSession.itemId) {
|
405
|
+
return;
|
415
406
|
}
|
416
407
|
|
417
|
-
|
418
|
-
|
408
|
+
return _objectSpread(_objectSpread({}, nextSession), {}, {
|
409
|
+
data: nextSession.data,
|
410
|
+
listKey: nextSession.listKey,
|
411
|
+
itemId: nextSession.itemId
|
419
412
|
});
|
420
|
-
|
421
|
-
if (nextSession) {
|
422
|
-
return nextSession;
|
423
|
-
}
|
424
413
|
},
|
425
414
|
end: async ({
|
426
415
|
res,
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
6
6
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
7
7
|
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
8
|
-
var _indexOfInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/index-of');
|
9
|
-
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
10
8
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
11
9
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
12
10
|
require('@babel/runtime-corejs3/core-js-stable/url');
|
@@ -39,8 +37,6 @@ function _interopNamespace(e) {
|
|
39
37
|
}
|
40
38
|
|
41
39
|
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
42
|
-
var _indexOfInstanceProperty__default = /*#__PURE__*/_interopDefault(_indexOfInstanceProperty);
|
43
|
-
var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
|
44
40
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
45
41
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
46
42
|
var url__default = /*#__PURE__*/_interopDefault(url);
|
@@ -199,7 +195,7 @@ const authTemplate = ({
|
|
199
195
|
return authOut;
|
200
196
|
};
|
201
197
|
|
202
|
-
const _excluded = ["get"
|
198
|
+
const _excluded = ["get"];
|
203
199
|
/**
|
204
200
|
* createAuth function
|
205
201
|
*
|
@@ -238,8 +234,6 @@ function createAuth({
|
|
238
234
|
context,
|
239
235
|
isValidSession
|
240
236
|
}) => {
|
241
|
-
var _context;
|
242
|
-
|
243
237
|
const {
|
244
238
|
req,
|
245
239
|
session
|
@@ -247,7 +241,7 @@ function createAuth({
|
|
247
241
|
const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
248
242
|
|
249
243
|
if (isValidSession) {
|
250
|
-
if (pathname === `${customPath}/api/auth/signin`) {
|
244
|
+
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)) {
|
251
245
|
return {
|
252
246
|
kind: 'redirect',
|
253
247
|
to: `${customPath}`
|
@@ -264,14 +258,14 @@ function createAuth({
|
|
264
258
|
return;
|
265
259
|
}
|
266
260
|
|
267
|
-
if (_includesInstanceProperty__default["default"](pathname).call(pathname, '/_next/') || _includesInstanceProperty__default["default"](pathname).call(pathname, '/api/auth/')) {
|
261
|
+
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)) {
|
268
262
|
return;
|
269
263
|
}
|
270
264
|
|
271
|
-
if (!session && !_includesInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/api/auth/`)
|
265
|
+
if (!session && !_includesInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/api/auth/`)) {
|
272
266
|
return {
|
273
267
|
kind: 'redirect',
|
274
|
-
to: `${customPath}/api/auth/signin`
|
268
|
+
to: (pages === null || pages === void 0 ? void 0 : pages.signIn) || `${customPath}/api/auth/signin`
|
275
269
|
};
|
276
270
|
}
|
277
271
|
};
|
@@ -373,53 +367,48 @@ function createAuth({
|
|
373
367
|
|
374
368
|
|
375
369
|
const withItemData = _sessionStrategy => {
|
376
|
-
const
|
377
|
-
get,
|
378
|
-
start
|
379
|
-
} = _sessionStrategy,
|
380
|
-
sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
|
370
|
+
const sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
|
381
371
|
|
382
372
|
return _objectSpread(_objectSpread({}, sessionStrategy), {}, {
|
383
|
-
start: async ({
|
384
|
-
|
385
|
-
}) => {
|
386
|
-
console.log('start');
|
387
|
-
const session = await start({
|
388
|
-
res
|
389
|
-
});
|
390
|
-
return session;
|
373
|
+
start: async () => {
|
374
|
+
return 'false';
|
391
375
|
},
|
392
376
|
get: async ({
|
393
|
-
req
|
377
|
+
req,
|
378
|
+
createContext
|
394
379
|
}) => {
|
395
|
-
var _req$headers$authoriz;
|
380
|
+
var _req$headers, _req$headers$authoriz;
|
396
381
|
|
382
|
+
const sudoContext = createContext({
|
383
|
+
sudo: true
|
384
|
+
});
|
397
385
|
const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
386
|
+
let nextSession;
|
398
387
|
|
399
388
|
if (_includesInstanceProperty__default["default"](pathname).call(pathname, '/api/auth')) {
|
400
389
|
return;
|
401
390
|
}
|
402
391
|
|
403
|
-
if (((_req$headers
|
404
|
-
|
405
|
-
|
406
|
-
const token = await jwt.getToken({
|
392
|
+
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') {
|
393
|
+
nextSession = await jwt.getToken({
|
407
394
|
req,
|
408
395
|
secret: sessionSecret
|
409
396
|
});
|
397
|
+
} else {
|
398
|
+
nextSession = await react.getSession({
|
399
|
+
req
|
400
|
+
});
|
401
|
+
}
|
410
402
|
|
411
|
-
|
412
|
-
|
413
|
-
}
|
403
|
+
if (!nextSession || !nextSession.listKey || nextSession.listKey !== listKey || !nextSession.itemId || !sudoContext.query[listKey] || !nextSession.itemId) {
|
404
|
+
return;
|
414
405
|
}
|
415
406
|
|
416
|
-
|
417
|
-
|
407
|
+
return _objectSpread(_objectSpread({}, nextSession), {}, {
|
408
|
+
data: nextSession.data,
|
409
|
+
listKey: nextSession.listKey,
|
410
|
+
itemId: nextSession.itemId
|
418
411
|
});
|
419
|
-
|
420
|
-
if (nextSession) {
|
421
|
-
return nextSession;
|
422
|
-
}
|
423
412
|
},
|
424
413
|
end: async ({
|
425
414
|
res,
|
@@ -1,8 +1,6 @@
|
|
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';
|
6
4
|
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
7
5
|
import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
8
6
|
import _URL from '@babel/runtime-corejs3/core-js-stable/url';
|
@@ -165,7 +163,7 @@ const authTemplate = ({
|
|
165
163
|
return authOut;
|
166
164
|
};
|
167
165
|
|
168
|
-
const _excluded = ["get"
|
166
|
+
const _excluded = ["get"];
|
169
167
|
/**
|
170
168
|
* createAuth function
|
171
169
|
*
|
@@ -204,8 +202,6 @@ function createAuth({
|
|
204
202
|
context,
|
205
203
|
isValidSession
|
206
204
|
}) => {
|
207
|
-
var _context;
|
208
|
-
|
209
205
|
const {
|
210
206
|
req,
|
211
207
|
session
|
@@ -213,7 +209,7 @@ function createAuth({
|
|
213
209
|
const pathname = url.parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
214
210
|
|
215
211
|
if (isValidSession) {
|
216
|
-
if (pathname === `${customPath}/api/auth/signin`) {
|
212
|
+
if (pathname === `${customPath}/api/auth/signin` || pages !== null && pages !== void 0 && pages.signIn && _includesInstanceProperty(pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.signIn)) {
|
217
213
|
return {
|
218
214
|
kind: 'redirect',
|
219
215
|
to: `${customPath}`
|
@@ -230,14 +226,14 @@ function createAuth({
|
|
230
226
|
return;
|
231
227
|
}
|
232
228
|
|
233
|
-
if (_includesInstanceProperty(pathname).call(pathname, '/_next/') || _includesInstanceProperty(pathname).call(pathname, '/api/auth/')) {
|
229
|
+
if (_includesInstanceProperty(pathname).call(pathname, '/_next/') || _includesInstanceProperty(pathname).call(pathname, '/api/auth/') || pages !== null && pages !== void 0 && pages.signIn && _includesInstanceProperty(pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.signIn) || pages !== null && pages !== void 0 && pages.error && _includesInstanceProperty(pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.error) || pages !== null && pages !== void 0 && pages.signOut && _includesInstanceProperty(pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.signOut)) {
|
234
230
|
return;
|
235
231
|
}
|
236
232
|
|
237
|
-
if (!session && !_includesInstanceProperty(pathname).call(pathname, `${customPath}/api/auth/`)
|
233
|
+
if (!session && !_includesInstanceProperty(pathname).call(pathname, `${customPath}/api/auth/`)) {
|
238
234
|
return {
|
239
235
|
kind: 'redirect',
|
240
|
-
to: `${customPath}/api/auth/signin`
|
236
|
+
to: (pages === null || pages === void 0 ? void 0 : pages.signIn) || `${customPath}/api/auth/signin`
|
241
237
|
};
|
242
238
|
}
|
243
239
|
};
|
@@ -339,53 +335,48 @@ function createAuth({
|
|
339
335
|
|
340
336
|
|
341
337
|
const withItemData = _sessionStrategy => {
|
342
|
-
const
|
343
|
-
get,
|
344
|
-
start
|
345
|
-
} = _sessionStrategy,
|
346
|
-
sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
|
338
|
+
const sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
|
347
339
|
|
348
340
|
return _objectSpread(_objectSpread({}, sessionStrategy), {}, {
|
349
|
-
start: async ({
|
350
|
-
|
351
|
-
}) => {
|
352
|
-
console.log('start');
|
353
|
-
const session = await start({
|
354
|
-
res
|
355
|
-
});
|
356
|
-
return session;
|
341
|
+
start: async () => {
|
342
|
+
return 'false';
|
357
343
|
},
|
358
344
|
get: async ({
|
359
|
-
req
|
345
|
+
req,
|
346
|
+
createContext
|
360
347
|
}) => {
|
361
|
-
var _req$headers$authoriz;
|
348
|
+
var _req$headers, _req$headers$authoriz;
|
362
349
|
|
350
|
+
const sudoContext = createContext({
|
351
|
+
sudo: true
|
352
|
+
});
|
363
353
|
const pathname = url.parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
354
|
+
let nextSession;
|
364
355
|
|
365
356
|
if (_includesInstanceProperty(pathname).call(pathname, '/api/auth')) {
|
366
357
|
return;
|
367
358
|
}
|
368
359
|
|
369
|
-
if (((_req$headers
|
370
|
-
|
371
|
-
|
372
|
-
const token = await getToken({
|
360
|
+
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') {
|
361
|
+
nextSession = await getToken({
|
373
362
|
req,
|
374
363
|
secret: sessionSecret
|
375
364
|
});
|
365
|
+
} else {
|
366
|
+
nextSession = await getSession({
|
367
|
+
req
|
368
|
+
});
|
369
|
+
}
|
376
370
|
|
377
|
-
|
378
|
-
|
379
|
-
}
|
371
|
+
if (!nextSession || !nextSession.listKey || nextSession.listKey !== listKey || !nextSession.itemId || !sudoContext.query[listKey] || !nextSession.itemId) {
|
372
|
+
return;
|
380
373
|
}
|
381
374
|
|
382
|
-
|
383
|
-
|
375
|
+
return _objectSpread(_objectSpread({}, nextSession), {}, {
|
376
|
+
data: nextSession.data,
|
377
|
+
listKey: nextSession.listKey,
|
378
|
+
itemId: nextSession.itemId
|
384
379
|
});
|
385
|
-
|
386
|
-
if (nextSession) {
|
387
|
-
return nextSession;
|
388
|
-
}
|
389
380
|
},
|
390
381
|
end: async ({
|
391
382
|
res,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@opensaas/keystone-nextjs-auth",
|
3
|
-
"version": "
|
3
|
+
"version": "22.1.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",
|
@@ -17,16 +17,14 @@
|
|
17
17
|
},
|
18
18
|
"devDependencies": {
|
19
19
|
"@keystone-6/core": "^1.1.0",
|
20
|
-
"next": "12.1.0",
|
21
20
|
"react": "^17.0.2"
|
22
21
|
},
|
23
22
|
"peerDependencies": {
|
24
23
|
"@keystone-6/core": "^1.1.0",
|
25
|
-
"next": "12.1.0",
|
26
24
|
"react": "^17.0.2"
|
27
25
|
},
|
28
26
|
"engines": {
|
29
|
-
"node": "^
|
27
|
+
"node": "^14.13 || >= 16.13"
|
30
28
|
},
|
31
29
|
"publishConfig": {
|
32
30
|
"access": "public"
|