@opensaas/keystone-nextjs-auth 13.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 +6 -0
- package/dist/declarations/src/pages/NextAuthPage.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +1 -13
- package/dist/opensaas-keystone-nextjs-auth.cjs.dev.js +3 -3
- package/dist/opensaas-keystone-nextjs-auth.cjs.prod.js +3 -3
- package/dist/opensaas-keystone-nextjs-auth.esm.js +3 -3
- package/package.json +4 -6
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.dev.js +6 -6
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.prod.js +6 -6
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.esm.js +6 -6
- package/src/index.ts +1 -1
- package/src/pages/NextAuthPage.tsx +7 -7
- package/src/templates/auth.ts +2 -2
- package/src/types.ts +1 -16
package/CHANGELOG.md
CHANGED
@@ -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;
|
@@ -164,7 +164,7 @@ const getSchemaExtension = ({
|
|
164
164
|
const template = `
|
165
165
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
166
166
|
import { nextAuthProviders as Providers } from '@opensaas/keystone-nextjs-auth';
|
167
|
-
import {
|
167
|
+
import { query } from '.keystone/api';
|
168
168
|
import keystoneConfig from '../../../../../keystone';
|
169
169
|
|
170
170
|
export default getNextAuthPage({
|
@@ -177,7 +177,7 @@ export default getNextAuthPage({
|
|
177
177
|
profileMap: <%- JSON.stringify(profileMap) %>,
|
178
178
|
autoCreate: <%= autoCreate %>,
|
179
179
|
providers: keystoneConfig.providers,
|
180
|
-
|
180
|
+
query,
|
181
181
|
});
|
182
182
|
`;
|
183
183
|
const authTemplate = ({
|
@@ -448,7 +448,7 @@ function createAuth({
|
|
448
448
|
const headers = (_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.headers;
|
449
449
|
const host = headers ? headers['x-forwarded-host'] || headers.host : null;
|
450
450
|
const thisUrl = headers !== null && headers !== void 0 && headers.referer ? new _URL__default['default'](headers.referer) : undefined;
|
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().
|
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;
|
452
452
|
return accessingInitPage || ((_keystoneConfig$ui2 = keystoneConfig.ui) !== null && _keystoneConfig$ui2 !== void 0 && _keystoneConfig$ui2.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined);
|
453
453
|
}
|
454
454
|
});
|
@@ -164,7 +164,7 @@ const getSchemaExtension = ({
|
|
164
164
|
const template = `
|
165
165
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
166
166
|
import { nextAuthProviders as Providers } from '@opensaas/keystone-nextjs-auth';
|
167
|
-
import {
|
167
|
+
import { query } from '.keystone/api';
|
168
168
|
import keystoneConfig from '../../../../../keystone';
|
169
169
|
|
170
170
|
export default getNextAuthPage({
|
@@ -177,7 +177,7 @@ export default getNextAuthPage({
|
|
177
177
|
profileMap: <%- JSON.stringify(profileMap) %>,
|
178
178
|
autoCreate: <%= autoCreate %>,
|
179
179
|
providers: keystoneConfig.providers,
|
180
|
-
|
180
|
+
query,
|
181
181
|
});
|
182
182
|
`;
|
183
183
|
const authTemplate = ({
|
@@ -448,7 +448,7 @@ function createAuth({
|
|
448
448
|
const headers = (_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.headers;
|
449
449
|
const host = headers ? headers['x-forwarded-host'] || headers.host : null;
|
450
450
|
const thisUrl = headers !== null && headers !== void 0 && headers.referer ? new _URL__default['default'](headers.referer) : undefined;
|
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().
|
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;
|
452
452
|
return accessingInitPage || ((_keystoneConfig$ui2 = keystoneConfig.ui) !== null && _keystoneConfig$ui2 !== void 0 && _keystoneConfig$ui2.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined);
|
453
453
|
}
|
454
454
|
});
|
@@ -127,7 +127,7 @@ const getSchemaExtension = ({
|
|
127
127
|
const template = `
|
128
128
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
129
129
|
import { nextAuthProviders as Providers } from '@opensaas/keystone-nextjs-auth';
|
130
|
-
import {
|
130
|
+
import { query } from '.keystone/api';
|
131
131
|
import keystoneConfig from '../../../../../keystone';
|
132
132
|
|
133
133
|
export default getNextAuthPage({
|
@@ -140,7 +140,7 @@ export default getNextAuthPage({
|
|
140
140
|
profileMap: <%- JSON.stringify(profileMap) %>,
|
141
141
|
autoCreate: <%= autoCreate %>,
|
142
142
|
providers: keystoneConfig.providers,
|
143
|
-
|
143
|
+
query,
|
144
144
|
});
|
145
145
|
`;
|
146
146
|
const authTemplate = ({
|
@@ -411,7 +411,7 @@ function createAuth({
|
|
411
411
|
const headers = (_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.headers;
|
412
412
|
const host = headers ? headers['x-forwarded-host'] || headers.host : null;
|
413
413
|
const thisUrl = headers !== null && headers !== void 0 && headers.referer ? new _URL(headers.referer) : undefined;
|
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().
|
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;
|
415
415
|
return accessingInitPage || ((_keystoneConfig$ui2 = keystoneConfig.ui) !== null && _keystoneConfig$ui2 !== void 0 && _keystoneConfig$ui2.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined);
|
416
416
|
}
|
417
417
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
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",
|
@@ -10,21 +10,19 @@
|
|
10
10
|
"@babel/runtime-corejs3": "^7.15.3",
|
11
11
|
"@graphql-tools/merge": "^6.2.14",
|
12
12
|
"@keystone-next/admin-ui-utils": "^6.0.0",
|
13
|
-
"@keystone-next/fields": "^15.0.0",
|
14
|
-
"@keystone-next/types": "^25.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
|
},
|
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
|
},
|
@@ -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
|
},
|
package/src/index.ts
CHANGED
@@ -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
|
@@ -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/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
|
|
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];
|