@opensaas/keystone-nextjs-auth 12.0.2 → 14.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 +24 -0
- package/dist/declarations/src/gql/getBaseAuthSchema.d.ts +1 -1
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/lib/findMatchingIdentity.d.ts +1 -1
- package/dist/declarations/src/lib/validateNextAuth.d.ts +1 -1
- package/dist/declarations/src/pages/NextAuthPage.d.ts +2 -2
- package/dist/declarations/src/schema.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +1 -13
- package/dist/opensaas-keystone-nextjs-auth.cjs.dev.js +14 -9
- package/dist/opensaas-keystone-nextjs-auth.cjs.prod.js +14 -9
- package/dist/opensaas-keystone-nextjs-auth.esm.js +12 -7
- package/package.json +6 -8
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.dev.js +7 -7
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.prod.js +7 -7
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.esm.js +7 -8
- package/src/gql/getBaseAuthSchema.ts +1 -1
- package/src/gql/getInitFirstItemSchema.ts +20 -6
- package/src/index.ts +2 -2
- package/src/lib/findMatchingIdentity.ts +1 -1
- package/src/lib/validateNextAuth.ts +3 -3
- package/src/pages/NextAuthPage.tsx +8 -8
- package/src/schema.ts +1 -1
- package/src/templates/auth.ts +2 -2
- package/src/templates/next-config.ts +7 -2
- package/src/types.ts +1 -16
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# @opensaas-keystone/nextjs-auth
|
2
2
|
|
3
|
+
## 14.0.0
|
4
|
+
|
5
|
+
### Major Changes
|
6
|
+
|
7
|
+
- 5a64376: Upgrade to keystone-next version 26
|
8
|
+
|
9
|
+
## 13.0.2
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 06cf34e: fix up next-config
|
14
|
+
|
15
|
+
## 13.0.1
|
16
|
+
|
17
|
+
### Patch Changes
|
18
|
+
|
19
|
+
- fb84793: next 11 fixes for next-config
|
20
|
+
|
21
|
+
## 13.0.0
|
22
|
+
|
23
|
+
### Major Changes
|
24
|
+
|
25
|
+
- e5d413a: Keystone Version upgrade to 25.0.0
|
26
|
+
|
3
27
|
## 12.0.2
|
4
28
|
|
5
29
|
### Patch Changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { GraphQLSchemaExtension } from '@keystone-next/types';
|
1
|
+
import type { GraphQLSchemaExtension } from '@keystone-next/keystone/types';
|
2
2
|
import { AuthGqlNames } from '../types';
|
3
3
|
export declare function getBaseAuthSchema<I extends string, S extends string>({ listKey, gqlNames, }: {
|
4
4
|
listKey: string;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BaseGeneratedListTypes, KeystoneConfig } from '@keystone-next/types';
|
1
|
+
import { BaseGeneratedListTypes, KeystoneConfig } from '@keystone-next/keystone/types';
|
2
2
|
import { AuthConfig, KeystoneAuthConfig } from './types';
|
3
3
|
export declare const nextAuthProviders: import("next-auth/providers").BuiltInProviders;
|
4
4
|
/**
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { KeystoneListsAPI } from '@keystone-next/types';
|
1
|
+
import type { KeystoneListsAPI } from '@keystone-next/keystone/types';
|
2
2
|
import { AuthTokenRequestErrorCode } from '../types';
|
3
3
|
export declare function findMatchingIdentity(identityField: string, identity: string, itemAPI: KeystoneListsAPI<any>[string]): Promise<{
|
4
4
|
success: false;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { KeystoneListsAPI } from '@keystone-next/types';
|
1
|
+
import type { KeystoneListsAPI } from '@keystone-next/keystone/types';
|
2
2
|
import { NextAuthErrorCode } from '../types';
|
3
3
|
export declare function validateNextAuth(list: any, identityField: string, identity: string, protectIdentities: boolean, itemAPI: KeystoneListsAPI<any>[string]): Promise<{
|
4
4
|
success: false;
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { Provider } from 'next-auth/providers';
|
2
|
-
import type { KeystoneListsAPI } from '@keystone-next/types';
|
2
|
+
import type { KeystoneListsAPI } from '@keystone-next/keystone/types';
|
3
3
|
declare type NextAuthPageProps = {
|
4
4
|
identityField: string;
|
5
5
|
mutationName: string;
|
6
6
|
providers: Provider[];
|
7
|
-
|
7
|
+
query: KeystoneListsAPI<any>;
|
8
8
|
sessionData: string;
|
9
9
|
listKey: string;
|
10
10
|
autoCreate: boolean;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ExtendGraphqlSchema } from '@keystone-next/types';
|
1
|
+
import { ExtendGraphqlSchema } from '@keystone-next/keystone/types';
|
2
2
|
import { AuthGqlNames } from './types';
|
3
3
|
export declare const getSchemaExtension: ({ identityField, listKey, gqlNames, }: {
|
4
4
|
identityField: string;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BaseGeneratedListTypes,
|
1
|
+
import { BaseGeneratedListTypes, KeystoneConfig } from '@keystone-next/keystone/types';
|
2
2
|
import { Provider } from 'next-auth/providers';
|
3
3
|
export declare type AuthGqlNames = {
|
4
4
|
CreateInitialInput: string;
|
@@ -8,18 +8,6 @@ export declare type AuthGqlNames = {
|
|
8
8
|
ItemAuthenticationWithPasswordSuccess: string;
|
9
9
|
ItemAuthenticationWithPasswordFailure: string;
|
10
10
|
};
|
11
|
-
export declare type SendTokenFn = (args: {
|
12
|
-
itemId: string | number;
|
13
|
-
identity: string;
|
14
|
-
token: string;
|
15
|
-
context: KeystoneContext;
|
16
|
-
}) => Promise<void> | void;
|
17
|
-
export declare type AuthTokenTypeConfig = {
|
18
|
-
/** Called when a user should be sent the magic signin token they requested */
|
19
|
-
sendToken: SendTokenFn;
|
20
|
-
/** How long do tokens stay valid for from time of issue, in minutes * */
|
21
|
-
tokensValidForMins?: number;
|
22
|
-
};
|
23
11
|
export declare type NextAuthSession = {
|
24
12
|
listKey: string;
|
25
13
|
itemId: string;
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
5
5
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
6
6
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
7
|
-
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
8
7
|
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
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
10
|
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
11
11
|
var url = require('url');
|
@@ -13,8 +13,8 @@ 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 _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
17
16
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
17
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
18
18
|
var merge = require('@graphql-tools/merge');
|
19
19
|
|
20
20
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
@@ -39,16 +39,16 @@ function _interopNamespace(e) {
|
|
39
39
|
return Object.freeze(n);
|
40
40
|
}
|
41
41
|
|
42
|
-
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
43
42
|
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
43
|
+
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
44
44
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
45
45
|
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
46
46
|
var url__default = /*#__PURE__*/_interopDefault(url);
|
47
47
|
var Providers__default = /*#__PURE__*/_interopDefault(Providers);
|
48
48
|
var cookie__namespace = /*#__PURE__*/_interopNamespace(cookie);
|
49
49
|
var ejs__default = /*#__PURE__*/_interopDefault(ejs);
|
50
|
-
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
51
50
|
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
51
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
52
52
|
|
53
53
|
const template$1 = `
|
54
54
|
const Path = require('path');
|
@@ -56,6 +56,12 @@ const Path = require('path');
|
|
56
56
|
const withPreconstruct = require('@preconstruct/next');
|
57
57
|
|
58
58
|
module.exports = withPreconstruct({
|
59
|
+
typescript: {
|
60
|
+
ignoreBuildErrors: true,
|
61
|
+
},
|
62
|
+
eslint: {
|
63
|
+
ignoreDuringBuilds: true,
|
64
|
+
},
|
59
65
|
webpack(config, { isServer }) {
|
60
66
|
config.resolve.alias = {
|
61
67
|
...config.resolve.alias,
|
@@ -68,8 +74,7 @@ module.exports = withPreconstruct({
|
|
68
74
|
if (isServer) {
|
69
75
|
config.externals = [
|
70
76
|
...config.externals,
|
71
|
-
/@keystone-next\\/keystone(?!\\/___internal-do-not-use-will-break-in-patch\\/admin-ui\\/id-field-view)/,
|
72
|
-
/@keystone-next\\/types/,
|
77
|
+
/@keystone-next\\/keystone(?!\\/___internal-do-not-use-will-break-in-patch\\/admin-ui\\/id-field-view|\\/fields\\/types\\/[^\\/]+\\/views)/,
|
73
78
|
/.prisma\\/client/
|
74
79
|
];
|
75
80
|
}
|
@@ -159,7 +164,7 @@ const getSchemaExtension = ({
|
|
159
164
|
const template = `
|
160
165
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
161
166
|
import { nextAuthProviders as Providers } from '@opensaas/keystone-nextjs-auth';
|
162
|
-
import {
|
167
|
+
import { query } from '.keystone/api';
|
163
168
|
import keystoneConfig from '../../../../../keystone';
|
164
169
|
|
165
170
|
export default getNextAuthPage({
|
@@ -172,7 +177,7 @@ export default getNextAuthPage({
|
|
172
177
|
profileMap: <%- JSON.stringify(profileMap) %>,
|
173
178
|
autoCreate: <%= autoCreate %>,
|
174
179
|
providers: keystoneConfig.providers,
|
175
|
-
|
180
|
+
query,
|
176
181
|
});
|
177
182
|
`;
|
178
183
|
const authTemplate = ({
|
@@ -443,7 +448,7 @@ function createAuth({
|
|
443
448
|
const headers = (_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.headers;
|
444
449
|
const host = headers ? headers['x-forwarded-host'] || headers.host : null;
|
445
450
|
const thisUrl = headers !== null && headers !== void 0 && headers.referer ? new _URL__default['default'](headers.referer) : undefined;
|
446
|
-
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().
|
451
|
+
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;
|
447
452
|
return accessingInitPage || ((_keystoneConfig$ui2 = keystoneConfig.ui) !== null && _keystoneConfig$ui2 !== void 0 && _keystoneConfig$ui2.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined);
|
448
453
|
}
|
449
454
|
});
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
5
5
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
6
6
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
7
|
-
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
8
7
|
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
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
10
|
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
11
11
|
var url = require('url');
|
@@ -13,8 +13,8 @@ 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 _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
17
16
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
17
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
18
18
|
var merge = require('@graphql-tools/merge');
|
19
19
|
|
20
20
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
@@ -39,16 +39,16 @@ function _interopNamespace(e) {
|
|
39
39
|
return Object.freeze(n);
|
40
40
|
}
|
41
41
|
|
42
|
-
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
43
42
|
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
43
|
+
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
44
44
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
45
45
|
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
46
46
|
var url__default = /*#__PURE__*/_interopDefault(url);
|
47
47
|
var Providers__default = /*#__PURE__*/_interopDefault(Providers);
|
48
48
|
var cookie__namespace = /*#__PURE__*/_interopNamespace(cookie);
|
49
49
|
var ejs__default = /*#__PURE__*/_interopDefault(ejs);
|
50
|
-
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
51
50
|
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
51
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
52
52
|
|
53
53
|
const template$1 = `
|
54
54
|
const Path = require('path');
|
@@ -56,6 +56,12 @@ const Path = require('path');
|
|
56
56
|
const withPreconstruct = require('@preconstruct/next');
|
57
57
|
|
58
58
|
module.exports = withPreconstruct({
|
59
|
+
typescript: {
|
60
|
+
ignoreBuildErrors: true,
|
61
|
+
},
|
62
|
+
eslint: {
|
63
|
+
ignoreDuringBuilds: true,
|
64
|
+
},
|
59
65
|
webpack(config, { isServer }) {
|
60
66
|
config.resolve.alias = {
|
61
67
|
...config.resolve.alias,
|
@@ -68,8 +74,7 @@ module.exports = withPreconstruct({
|
|
68
74
|
if (isServer) {
|
69
75
|
config.externals = [
|
70
76
|
...config.externals,
|
71
|
-
/@keystone-next\\/keystone(?!\\/___internal-do-not-use-will-break-in-patch\\/admin-ui\\/id-field-view)/,
|
72
|
-
/@keystone-next\\/types/,
|
77
|
+
/@keystone-next\\/keystone(?!\\/___internal-do-not-use-will-break-in-patch\\/admin-ui\\/id-field-view|\\/fields\\/types\\/[^\\/]+\\/views)/,
|
73
78
|
/.prisma\\/client/
|
74
79
|
];
|
75
80
|
}
|
@@ -159,7 +164,7 @@ const getSchemaExtension = ({
|
|
159
164
|
const template = `
|
160
165
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
161
166
|
import { nextAuthProviders as Providers } from '@opensaas/keystone-nextjs-auth';
|
162
|
-
import {
|
167
|
+
import { query } from '.keystone/api';
|
163
168
|
import keystoneConfig from '../../../../../keystone';
|
164
169
|
|
165
170
|
export default getNextAuthPage({
|
@@ -172,7 +177,7 @@ export default getNextAuthPage({
|
|
172
177
|
profileMap: <%- JSON.stringify(profileMap) %>,
|
173
178
|
autoCreate: <%= autoCreate %>,
|
174
179
|
providers: keystoneConfig.providers,
|
175
|
-
|
180
|
+
query,
|
176
181
|
});
|
177
182
|
`;
|
178
183
|
const authTemplate = ({
|
@@ -443,7 +448,7 @@ function createAuth({
|
|
443
448
|
const headers = (_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.headers;
|
444
449
|
const host = headers ? headers['x-forwarded-host'] || headers.host : null;
|
445
450
|
const thisUrl = headers !== null && headers !== void 0 && headers.referer ? new _URL__default['default'](headers.referer) : undefined;
|
446
|
-
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().
|
451
|
+
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;
|
447
452
|
return accessingInitPage || ((_keystoneConfig$ui2 = keystoneConfig.ui) !== null && _keystoneConfig$ui2 !== void 0 && _keystoneConfig$ui2.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined);
|
448
453
|
}
|
449
454
|
});
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
2
2
|
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
3
|
-
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
4
3
|
import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
|
4
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
5
5
|
import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
6
6
|
import _URL from '@babel/runtime-corejs3/core-js-stable/url';
|
7
7
|
import url from 'url';
|
@@ -9,8 +9,8 @@ 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 _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
13
12
|
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
13
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
14
14
|
import { mergeSchemas } from '@graphql-tools/merge';
|
15
15
|
|
16
16
|
const template$1 = `
|
@@ -19,6 +19,12 @@ const Path = require('path');
|
|
19
19
|
const withPreconstruct = require('@preconstruct/next');
|
20
20
|
|
21
21
|
module.exports = withPreconstruct({
|
22
|
+
typescript: {
|
23
|
+
ignoreBuildErrors: true,
|
24
|
+
},
|
25
|
+
eslint: {
|
26
|
+
ignoreDuringBuilds: true,
|
27
|
+
},
|
22
28
|
webpack(config, { isServer }) {
|
23
29
|
config.resolve.alias = {
|
24
30
|
...config.resolve.alias,
|
@@ -31,8 +37,7 @@ module.exports = withPreconstruct({
|
|
31
37
|
if (isServer) {
|
32
38
|
config.externals = [
|
33
39
|
...config.externals,
|
34
|
-
/@keystone-next\\/keystone(?!\\/___internal-do-not-use-will-break-in-patch\\/admin-ui\\/id-field-view)/,
|
35
|
-
/@keystone-next\\/types/,
|
40
|
+
/@keystone-next\\/keystone(?!\\/___internal-do-not-use-will-break-in-patch\\/admin-ui\\/id-field-view|\\/fields\\/types\\/[^\\/]+\\/views)/,
|
36
41
|
/.prisma\\/client/
|
37
42
|
];
|
38
43
|
}
|
@@ -122,7 +127,7 @@ const getSchemaExtension = ({
|
|
122
127
|
const template = `
|
123
128
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
124
129
|
import { nextAuthProviders as Providers } from '@opensaas/keystone-nextjs-auth';
|
125
|
-
import {
|
130
|
+
import { query } from '.keystone/api';
|
126
131
|
import keystoneConfig from '../../../../../keystone';
|
127
132
|
|
128
133
|
export default getNextAuthPage({
|
@@ -135,7 +140,7 @@ export default getNextAuthPage({
|
|
135
140
|
profileMap: <%- JSON.stringify(profileMap) %>,
|
136
141
|
autoCreate: <%= autoCreate %>,
|
137
142
|
providers: keystoneConfig.providers,
|
138
|
-
|
143
|
+
query,
|
139
144
|
});
|
140
145
|
`;
|
141
146
|
const authTemplate = ({
|
@@ -406,7 +411,7 @@ function createAuth({
|
|
406
411
|
const headers = (_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.headers;
|
407
412
|
const host = headers ? headers['x-forwarded-host'] || headers.host : null;
|
408
413
|
const thisUrl = headers !== null && headers !== void 0 && headers.referer ? new _URL(headers.referer) : undefined;
|
409
|
-
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().
|
414
|
+
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;
|
410
415
|
return accessingInitPage || ((_keystoneConfig$ui2 = keystoneConfig.ui) !== null && _keystoneConfig$ui2 !== void 0 && _keystoneConfig$ui2.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined);
|
411
416
|
}
|
412
417
|
});
|
package/package.json
CHANGED
@@ -1,30 +1,28 @@
|
|
1
1
|
{
|
2
2
|
"name": "@opensaas/keystone-nextjs-auth",
|
3
|
-
"version": "
|
3
|
+
"version": "14.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.
|
9
|
+
"@babel/runtime": "^7.15.4",
|
10
10
|
"@babel/runtime-corejs3": "^7.15.3",
|
11
11
|
"@graphql-tools/merge": "^6.2.14",
|
12
|
-
"@keystone-next/admin-ui-utils": "^
|
13
|
-
"@keystone-next/fields": "^14.0.0",
|
14
|
-
"@keystone-next/types": "^24.0.0",
|
12
|
+
"@keystone-next/admin-ui-utils": "^6.0.0",
|
15
13
|
"@types/ejs": "^3.0.6",
|
16
14
|
"cookie": "^0.4.1",
|
17
15
|
"cross-fetch": "^3.1.4",
|
18
16
|
"ejs": "^3.1.6",
|
19
17
|
"fast-deep-equal": "^3.1.3",
|
20
|
-
"next-auth": "^3.
|
18
|
+
"next-auth": "^3.29.0"
|
21
19
|
},
|
22
20
|
"devDependencies": {
|
23
|
-
"@keystone-next/keystone": "^
|
21
|
+
"@keystone-next/keystone": "^26.0.0",
|
24
22
|
"react": "^17.0.2"
|
25
23
|
},
|
26
24
|
"peerDependencies": {
|
27
|
-
"@keystone-next/keystone": "^
|
25
|
+
"@keystone-next/keystone": "^26.0.0",
|
28
26
|
"react": "^17.0.2"
|
29
27
|
},
|
30
28
|
"engines": {
|
@@ -62,7 +62,7 @@ async function validateNextAuth(list, identityField, identity, protectIdentities
|
|
62
62
|
function NextAuthPage(props) {
|
63
63
|
const {
|
64
64
|
providers,
|
65
|
-
|
65
|
+
query,
|
66
66
|
identityField,
|
67
67
|
sessionData,
|
68
68
|
listKey,
|
@@ -71,15 +71,15 @@ function NextAuthPage(props) {
|
|
71
71
|
accountMap,
|
72
72
|
profileMap
|
73
73
|
} = props;
|
74
|
-
const list =
|
75
|
-
const
|
74
|
+
const list = query[listKey];
|
75
|
+
const queryAPI = query[listKey];
|
76
76
|
const protectIdentities = true;
|
77
77
|
return NextAuth__default['default']({
|
78
78
|
providers,
|
79
79
|
callbacks: {
|
80
80
|
async signIn(user, account, profile) {
|
81
81
|
const identity = user.id;
|
82
|
-
const result = await validateNextAuth(list, identityField, identity, protectIdentities,
|
82
|
+
const result = await validateNextAuth(list, identityField, identity, protectIdentities, queryAPI);
|
83
83
|
const data = {}; // eslint-disable-next-line no-restricted-syntax
|
84
84
|
|
85
85
|
for (const key in userMap) {
|
@@ -146,13 +146,13 @@ function NextAuthPage(props) {
|
|
146
146
|
const identity = token.sub;
|
147
147
|
|
148
148
|
if (!token.itemId) {
|
149
|
-
const result = await validateNextAuth(list, identityField, identity, protectIdentities,
|
149
|
+
const result = await validateNextAuth(list, identityField, identity, protectIdentities, queryAPI);
|
150
150
|
|
151
151
|
if (!result.success) {
|
152
152
|
return;
|
153
153
|
}
|
154
154
|
|
155
|
-
const data = await
|
155
|
+
const data = await query[listKey].findOne({
|
156
156
|
where: {
|
157
157
|
id: result.item.id
|
158
158
|
},
|
@@ -177,5 +177,5 @@ function NextAuthPage(props) {
|
|
177
177
|
}
|
178
178
|
const getNextAuthPage = props => () => NextAuthPage(_objectSpread({}, props));
|
179
179
|
|
180
|
-
exports
|
180
|
+
exports['default'] = NextAuthPage;
|
181
181
|
exports.getNextAuthPage = getNextAuthPage;
|
package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.prod.js
CHANGED
@@ -62,7 +62,7 @@ async function validateNextAuth(list, identityField, identity, protectIdentities
|
|
62
62
|
function NextAuthPage(props) {
|
63
63
|
const {
|
64
64
|
providers,
|
65
|
-
|
65
|
+
query,
|
66
66
|
identityField,
|
67
67
|
sessionData,
|
68
68
|
listKey,
|
@@ -71,15 +71,15 @@ function NextAuthPage(props) {
|
|
71
71
|
accountMap,
|
72
72
|
profileMap
|
73
73
|
} = props;
|
74
|
-
const list =
|
75
|
-
const
|
74
|
+
const list = query[listKey];
|
75
|
+
const queryAPI = query[listKey];
|
76
76
|
const protectIdentities = true;
|
77
77
|
return NextAuth__default['default']({
|
78
78
|
providers,
|
79
79
|
callbacks: {
|
80
80
|
async signIn(user, account, profile) {
|
81
81
|
const identity = user.id;
|
82
|
-
const result = await validateNextAuth(list, identityField, identity, protectIdentities,
|
82
|
+
const result = await validateNextAuth(list, identityField, identity, protectIdentities, queryAPI);
|
83
83
|
const data = {}; // eslint-disable-next-line no-restricted-syntax
|
84
84
|
|
85
85
|
for (const key in userMap) {
|
@@ -146,13 +146,13 @@ function NextAuthPage(props) {
|
|
146
146
|
const identity = token.sub;
|
147
147
|
|
148
148
|
if (!token.itemId) {
|
149
|
-
const result = await validateNextAuth(list, identityField, identity, protectIdentities,
|
149
|
+
const result = await validateNextAuth(list, identityField, identity, protectIdentities, queryAPI);
|
150
150
|
|
151
151
|
if (!result.success) {
|
152
152
|
return;
|
153
153
|
}
|
154
154
|
|
155
|
-
const data = await
|
155
|
+
const data = await query[listKey].findOne({
|
156
156
|
where: {
|
157
157
|
id: result.item.id
|
158
158
|
},
|
@@ -177,5 +177,5 @@ function NextAuthPage(props) {
|
|
177
177
|
}
|
178
178
|
const getNextAuthPage = props => () => NextAuthPage(_objectSpread({}, props));
|
179
179
|
|
180
|
-
exports
|
180
|
+
exports['default'] = NextAuthPage;
|
181
181
|
exports.getNextAuthPage = getNextAuthPage;
|
@@ -54,7 +54,7 @@ async function validateNextAuth(list, identityField, identity, protectIdentities
|
|
54
54
|
function NextAuthPage(props) {
|
55
55
|
const {
|
56
56
|
providers,
|
57
|
-
|
57
|
+
query,
|
58
58
|
identityField,
|
59
59
|
sessionData,
|
60
60
|
listKey,
|
@@ -63,15 +63,15 @@ function NextAuthPage(props) {
|
|
63
63
|
accountMap,
|
64
64
|
profileMap
|
65
65
|
} = props;
|
66
|
-
const list =
|
67
|
-
const
|
66
|
+
const list = query[listKey];
|
67
|
+
const queryAPI = query[listKey];
|
68
68
|
const protectIdentities = true;
|
69
69
|
return NextAuth({
|
70
70
|
providers,
|
71
71
|
callbacks: {
|
72
72
|
async signIn(user, account, profile) {
|
73
73
|
const identity = user.id;
|
74
|
-
const result = await validateNextAuth(list, identityField, identity, protectIdentities,
|
74
|
+
const result = await validateNextAuth(list, identityField, identity, protectIdentities, queryAPI);
|
75
75
|
const data = {}; // eslint-disable-next-line no-restricted-syntax
|
76
76
|
|
77
77
|
for (const key in userMap) {
|
@@ -138,13 +138,13 @@ function NextAuthPage(props) {
|
|
138
138
|
const identity = token.sub;
|
139
139
|
|
140
140
|
if (!token.itemId) {
|
141
|
-
const result = await validateNextAuth(list, identityField, identity, protectIdentities,
|
141
|
+
const result = await validateNextAuth(list, identityField, identity, protectIdentities, queryAPI);
|
142
142
|
|
143
143
|
if (!result.success) {
|
144
144
|
return;
|
145
145
|
}
|
146
146
|
|
147
|
-
const data = await
|
147
|
+
const data = await query[listKey].findOne({
|
148
148
|
where: {
|
149
149
|
id: result.item.id
|
150
150
|
},
|
@@ -169,5 +169,4 @@ function NextAuthPage(props) {
|
|
169
169
|
}
|
170
170
|
const getNextAuthPage = props => () => NextAuthPage(_objectSpread({}, props));
|
171
171
|
|
172
|
-
export default
|
173
|
-
export { getNextAuthPage };
|
172
|
+
export { NextAuthPage as default, getNextAuthPage };
|
@@ -1,5 +1,10 @@
|
|
1
|
-
import type { GraphQLSchemaExtension } from '@keystone-next/types';
|
2
|
-
import {
|
1
|
+
import type { GraphQLSchemaExtension } from '@keystone-next/keystone/types';
|
2
|
+
import {
|
3
|
+
assertInputObjectType,
|
4
|
+
GraphQLInputObjectType,
|
5
|
+
GraphQLSchema,
|
6
|
+
printType,
|
7
|
+
} from 'graphql';
|
3
8
|
|
4
9
|
import { AuthGqlNames, InitFirstItemConfig } from '../types';
|
5
10
|
|
@@ -24,7 +29,9 @@ export function getInitFirstItemSchema({
|
|
24
29
|
new GraphQLInputObjectType({
|
25
30
|
...createInputConfig,
|
26
31
|
fields: Object.fromEntries(
|
27
|
-
Object.entries(createInputConfig.fields).filter(([fieldKey]) =>
|
32
|
+
Object.entries(createInputConfig.fields).filter(([fieldKey]) =>
|
33
|
+
fieldsSet.has(fieldKey)
|
34
|
+
)
|
28
35
|
),
|
29
36
|
name: gqlNames.CreateInitialInput,
|
30
37
|
})
|
@@ -50,12 +57,19 @@ export function getInitFirstItemSchema({
|
|
50
57
|
const dbItemAPI = context.sudo().db.lists[listKey];
|
51
58
|
const count = await dbItemAPI.count({});
|
52
59
|
if (count !== 0) {
|
53
|
-
throw new Error(
|
60
|
+
throw new Error(
|
61
|
+
'Initial items can only be created when no items exist in that list'
|
62
|
+
);
|
54
63
|
}
|
55
64
|
|
56
65
|
// Update system state
|
57
|
-
const item = await dbItemAPI.createOne({
|
58
|
-
|
66
|
+
const item = await dbItemAPI.createOne({
|
67
|
+
data: { ...data, ...itemData },
|
68
|
+
});
|
69
|
+
const sessionToken = await context.startSession({
|
70
|
+
listKey,
|
71
|
+
itemId: item.id,
|
72
|
+
});
|
59
73
|
return { item, sessionToken };
|
60
74
|
},
|
61
75
|
},
|
package/src/index.ts
CHANGED
@@ -6,7 +6,7 @@ import {
|
|
6
6
|
KeystoneContext,
|
7
7
|
AdminUIConfig,
|
8
8
|
SessionStrategy,
|
9
|
-
} from '@keystone-next/types';
|
9
|
+
} from '@keystone-next/keystone/types';
|
10
10
|
import { getSession } from 'next-auth/client';
|
11
11
|
import Providers from 'next-auth/providers';
|
12
12
|
import * as cookie from 'cookie';
|
@@ -256,7 +256,7 @@ export function createAuth<GeneratedListTypes extends BaseGeneratedListTypes>({
|
|
256
256
|
const accessingInitPage =
|
257
257
|
thisUrl?.pathname === '/init' &&
|
258
258
|
thisUrl?.host === host &&
|
259
|
-
(await context.sudo().
|
259
|
+
(await context.sudo().query[listKey].count({})) === 0;
|
260
260
|
return (
|
261
261
|
accessingInitPage ||
|
262
262
|
(keystoneConfig.ui?.isAccessAllowed
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { KeystoneListsAPI } from '@keystone-next/types';
|
1
|
+
import type { KeystoneListsAPI } from '@keystone-next/keystone/types';
|
2
2
|
import { NextAuthErrorCode } from '../types';
|
3
3
|
import { findMatchingIdentity } from './findMatchingIdentity';
|
4
4
|
|
@@ -10,13 +10,13 @@ export async function validateNextAuth(
|
|
10
10
|
itemAPI: KeystoneListsAPI<any>[string]
|
11
11
|
): Promise<
|
12
12
|
| { success: false; code: NextAuthErrorCode }
|
13
|
-
| { success: true; item: { id: any;[prop: string]: any } }
|
13
|
+
| { success: true; item: { id: any; [prop: string]: any } }
|
14
14
|
> {
|
15
15
|
const match = await findMatchingIdentity(identityField, identity, itemAPI);
|
16
16
|
|
17
17
|
const { item } = match as {
|
18
18
|
success: true;
|
19
|
-
item: { id: any;[prop: string]: any };
|
19
|
+
item: { id: any; [prop: string]: any };
|
20
20
|
};
|
21
21
|
|
22
22
|
if (item) {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import NextAuth from 'next-auth';
|
2
2
|
import { Provider } from 'next-auth/providers';
|
3
|
-
import type { KeystoneListsAPI } from '@keystone-next/types';
|
3
|
+
import type { KeystoneListsAPI } from '@keystone-next/keystone/types';
|
4
4
|
import { validateNextAuth } from '../lib/validateNextAuth';
|
5
5
|
|
6
6
|
// Need to bring in correct props
|
@@ -8,7 +8,7 @@ type NextAuthPageProps = {
|
|
8
8
|
identityField: string;
|
9
9
|
mutationName: string;
|
10
10
|
providers: Provider[];
|
11
|
-
|
11
|
+
query: KeystoneListsAPI<any>;
|
12
12
|
sessionData: string;
|
13
13
|
listKey: string;
|
14
14
|
autoCreate: boolean;
|
@@ -20,7 +20,7 @@ type NextAuthPageProps = {
|
|
20
20
|
export default function NextAuthPage(props: NextAuthPageProps) {
|
21
21
|
const {
|
22
22
|
providers,
|
23
|
-
|
23
|
+
query,
|
24
24
|
identityField,
|
25
25
|
sessionData,
|
26
26
|
listKey,
|
@@ -29,8 +29,8 @@ export default function NextAuthPage(props: NextAuthPageProps) {
|
|
29
29
|
accountMap,
|
30
30
|
profileMap,
|
31
31
|
} = props;
|
32
|
-
const list =
|
33
|
-
const
|
32
|
+
const list = query[listKey];
|
33
|
+
const queryAPI = query[listKey];
|
34
34
|
const protectIdentities = true;
|
35
35
|
|
36
36
|
return NextAuth({
|
@@ -43,7 +43,7 @@ export default function NextAuthPage(props: NextAuthPageProps) {
|
|
43
43
|
identityField,
|
44
44
|
identity,
|
45
45
|
protectIdentities,
|
46
|
-
|
46
|
+
queryAPI
|
47
47
|
);
|
48
48
|
const data = {};
|
49
49
|
// eslint-disable-next-line no-restricted-syntax
|
@@ -113,14 +113,14 @@ export default function NextAuthPage(props: NextAuthPageProps) {
|
|
113
113
|
identityField,
|
114
114
|
identity,
|
115
115
|
protectIdentities,
|
116
|
-
|
116
|
+
queryAPI
|
117
117
|
);
|
118
118
|
|
119
119
|
if (!result.success) {
|
120
120
|
return;
|
121
121
|
}
|
122
122
|
|
123
|
-
const data = await
|
123
|
+
const data = await query[listKey].findOne({
|
124
124
|
where: { id: result.item.id },
|
125
125
|
query: sessionData || 'id',
|
126
126
|
});
|
package/src/schema.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { mergeSchemas } from '@graphql-tools/merge';
|
2
|
-
import { ExtendGraphqlSchema } from '@keystone-next/types';
|
2
|
+
import { ExtendGraphqlSchema } from '@keystone-next/keystone/types';
|
3
3
|
|
4
4
|
import { AuthGqlNames } from './types';
|
5
5
|
import { getBaseAuthSchema } from './gql/getBaseAuthSchema';
|
package/src/templates/auth.ts
CHANGED
@@ -4,7 +4,7 @@ import { AuthGqlNames } from '../types';
|
|
4
4
|
const template = `
|
5
5
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
6
6
|
import { nextAuthProviders as Providers } from '@opensaas/keystone-nextjs-auth';
|
7
|
-
import {
|
7
|
+
import { query } from '.keystone/api';
|
8
8
|
import keystoneConfig from '../../../../../keystone';
|
9
9
|
|
10
10
|
export default getNextAuthPage({
|
@@ -17,7 +17,7 @@ export default getNextAuthPage({
|
|
17
17
|
profileMap: <%- JSON.stringify(profileMap) %>,
|
18
18
|
autoCreate: <%= autoCreate %>,
|
19
19
|
providers: keystoneConfig.providers,
|
20
|
-
|
20
|
+
query,
|
21
21
|
});
|
22
22
|
`;
|
23
23
|
|
@@ -6,6 +6,12 @@ const Path = require('path');
|
|
6
6
|
const withPreconstruct = require('@preconstruct/next');
|
7
7
|
|
8
8
|
module.exports = withPreconstruct({
|
9
|
+
typescript: {
|
10
|
+
ignoreBuildErrors: true,
|
11
|
+
},
|
12
|
+
eslint: {
|
13
|
+
ignoreDuringBuilds: true,
|
14
|
+
},
|
9
15
|
webpack(config, { isServer }) {
|
10
16
|
config.resolve.alias = {
|
11
17
|
...config.resolve.alias,
|
@@ -18,8 +24,7 @@ module.exports = withPreconstruct({
|
|
18
24
|
if (isServer) {
|
19
25
|
config.externals = [
|
20
26
|
...config.externals,
|
21
|
-
/@keystone-next\\/keystone(?!\\/___internal-do-not-use-will-break-in-patch\\/admin-ui\\/id-field-view)/,
|
22
|
-
/@keystone-next\\/types/,
|
27
|
+
/@keystone-next\\/keystone(?!\\/___internal-do-not-use-will-break-in-patch\\/admin-ui\\/id-field-view|\\/fields\\/types\\/[^\\/]+\\/views)/,
|
23
28
|
/.prisma\\/client/
|
24
29
|
];
|
25
30
|
}
|
package/src/types.ts
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
import {
|
2
2
|
BaseGeneratedListTypes,
|
3
|
-
KeystoneContext,
|
4
3
|
KeystoneConfig,
|
5
|
-
} from '@keystone-next/types';
|
4
|
+
} from '@keystone-next/keystone/types';
|
6
5
|
import { Provider } from 'next-auth/providers';
|
7
6
|
|
8
7
|
export type AuthGqlNames = {
|
@@ -14,20 +13,6 @@ export type AuthGqlNames = {
|
|
14
13
|
ItemAuthenticationWithPasswordFailure: string;
|
15
14
|
};
|
16
15
|
|
17
|
-
export type SendTokenFn = (args: {
|
18
|
-
itemId: string | number;
|
19
|
-
identity: string;
|
20
|
-
token: string;
|
21
|
-
context: KeystoneContext;
|
22
|
-
}) => Promise<void> | void;
|
23
|
-
|
24
|
-
export type AuthTokenTypeConfig = {
|
25
|
-
/** Called when a user should be sent the magic signin token they requested */
|
26
|
-
sendToken: SendTokenFn;
|
27
|
-
/** How long do tokens stay valid for from time of issue, in minutes * */
|
28
|
-
tokensValidForMins?: number;
|
29
|
-
};
|
30
|
-
|
31
16
|
export type NextAuthSession = { listKey: string; itemId: string; data: any };
|
32
17
|
|
33
18
|
export type NextAuthProviders = [Provider];
|