@opensaas/keystone-nextjs-auth 20.1.1 → 20.2.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 +10 -0
- package/dist/declarations/src/lib/validateNextAuth.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +1 -1
- package/dist/opensaas-keystone-nextjs-auth.cjs.dev.js +3 -0
- package/dist/opensaas-keystone-nextjs-auth.cjs.prod.js +3 -0
- package/dist/opensaas-keystone-nextjs-auth.esm.js +3 -0
- package/package.json +3 -3
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.dev.js +11 -9
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.prod.js +11 -9
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.esm.js +11 -9
- package/src/index.ts +4 -0
- package/src/lib/validateNextAuth.ts +0 -1
- package/src/pages/NextAuthPage.tsx +15 -13
- package/src/types.ts +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { KeystoneListsAPI } from '@keystone-6/core/types';
|
2
2
|
import { NextAuthErrorCode } from '../types';
|
3
|
-
export declare function validateNextAuth(
|
3
|
+
export declare function validateNextAuth(identityField: string, identity: string | number, protectIdentities: boolean, itemAPI: KeystoneListsAPI<any>[string]): Promise<{
|
4
4
|
success: false;
|
5
5
|
code: NextAuthErrorCode;
|
6
6
|
} | {
|
@@ -13,7 +13,7 @@ export declare type NextAuthSession = {
|
|
13
13
|
itemId: string;
|
14
14
|
data: any;
|
15
15
|
};
|
16
|
-
export declare type NextAuthProviders = [
|
16
|
+
export declare type NextAuthProviders = Provider[];
|
17
17
|
declare type KeytoneAuthProviders = {
|
18
18
|
providers: NextAuthProviders;
|
19
19
|
};
|
@@ -490,6 +490,9 @@ function createAuth({
|
|
490
490
|
session,
|
491
491
|
providers,
|
492
492
|
lists: _objectSpread({}, keystoneConfig.lists),
|
493
|
+
experimental: _objectSpread(_objectSpread({}, keystoneConfig.experimental), {}, {
|
494
|
+
generateNodeAPI: true
|
495
|
+
}),
|
493
496
|
extendGraphqlSchema: existingExtendGraphQLSchema ? schema => existingExtendGraphQLSchema(extendGraphqlSchema(schema)) : extendGraphqlSchema
|
494
497
|
});
|
495
498
|
};
|
@@ -486,6 +486,9 @@ function createAuth({
|
|
486
486
|
session,
|
487
487
|
providers,
|
488
488
|
lists: _objectSpread({}, keystoneConfig.lists),
|
489
|
+
experimental: _objectSpread(_objectSpread({}, keystoneConfig.experimental), {}, {
|
490
|
+
generateNodeAPI: true
|
491
|
+
}),
|
489
492
|
extendGraphqlSchema: existingExtendGraphQLSchema ? schema => existingExtendGraphQLSchema(extendGraphqlSchema(schema)) : extendGraphqlSchema
|
490
493
|
});
|
491
494
|
};
|
@@ -457,6 +457,9 @@ function createAuth({
|
|
457
457
|
session,
|
458
458
|
providers,
|
459
459
|
lists: _objectSpread({}, keystoneConfig.lists),
|
460
|
+
experimental: _objectSpread(_objectSpread({}, keystoneConfig.experimental), {}, {
|
461
|
+
generateNodeAPI: true
|
462
|
+
}),
|
460
463
|
extendGraphqlSchema: existingExtendGraphQLSchema ? schema => existingExtendGraphQLSchema(extendGraphqlSchema(schema)) : extendGraphqlSchema
|
461
464
|
});
|
462
465
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@opensaas/keystone-nextjs-auth",
|
3
|
-
"version": "20.
|
3
|
+
"version": "20.2.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,11 +10,11 @@
|
|
10
10
|
"@babel/runtime-corejs3": "^7.16.8",
|
11
11
|
"@types/ejs": "^3.1.0",
|
12
12
|
"cookie": "^0.4.1",
|
13
|
-
"cross-fetch": "^3.1.
|
13
|
+
"cross-fetch": "^3.1.5",
|
14
14
|
"ejs": "^3.1.6",
|
15
15
|
"fast-deep-equal": "^3.1.3",
|
16
16
|
"graphql": "^15.8.0",
|
17
|
-
"next-auth": "^4.1.
|
17
|
+
"next-auth": "^4.1.2"
|
18
18
|
},
|
19
19
|
"devDependencies": {
|
20
20
|
"@keystone-6/core": "^1.0.1",
|
@@ -37,7 +37,7 @@ async function findMatchingIdentity(identityField, identity, queryAPI) {
|
|
37
37
|
};
|
38
38
|
}
|
39
39
|
|
40
|
-
async function validateNextAuth(
|
40
|
+
async function validateNextAuth(identityField, identity, protectIdentities, itemAPI) {
|
41
41
|
const match = await findMatchingIdentity(identityField, identity, itemAPI);
|
42
42
|
const {
|
43
43
|
item
|
@@ -87,9 +87,11 @@ function NextAuthPage(props) {
|
|
87
87
|
identity = user.id;
|
88
88
|
} else if (typeof user.id === 'number') {
|
89
89
|
identity = user.id;
|
90
|
+
} else {
|
91
|
+
identity = 0;
|
90
92
|
}
|
91
93
|
|
92
|
-
const result = await validateNextAuth(
|
94
|
+
const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
|
93
95
|
const data = {}; // eslint-disable-next-line no-restricted-syntax
|
94
96
|
|
95
97
|
for (const key in userMap) {
|
@@ -114,11 +116,11 @@ function NextAuthPage(props) {
|
|
114
116
|
|
115
117
|
if (!result.success) {
|
116
118
|
if (!autoCreate) {
|
117
|
-
console.log('
|
119
|
+
console.log('`autoCreate` if set to `false`, skipping user auto-creation');
|
118
120
|
return false;
|
119
121
|
}
|
120
122
|
|
121
|
-
console.log('
|
123
|
+
console.log('`autoCreate` if set to `true`, auto-creating a new user');
|
122
124
|
const createUser = await list.createOne({
|
123
125
|
data
|
124
126
|
}).then(returned => {
|
@@ -130,10 +132,10 @@ function NextAuthPage(props) {
|
|
130
132
|
});
|
131
133
|
console.log('Created User', createUser);
|
132
134
|
return createUser;
|
133
|
-
}
|
134
|
-
|
135
|
-
|
136
|
-
|
135
|
+
} // await list.updateOne({where: {id: result.item.id}, data});
|
136
|
+
|
137
|
+
|
138
|
+
return result.success;
|
137
139
|
},
|
138
140
|
|
139
141
|
async redirect({
|
@@ -162,7 +164,7 @@ function NextAuthPage(props) {
|
|
162
164
|
const identity = token.sub;
|
163
165
|
|
164
166
|
if (!token.itemId) {
|
165
|
-
const result = await validateNextAuth(
|
167
|
+
const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
|
166
168
|
|
167
169
|
if (!result.success) {
|
168
170
|
return;
|
package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.prod.js
CHANGED
@@ -37,7 +37,7 @@ async function findMatchingIdentity(identityField, identity, queryAPI) {
|
|
37
37
|
};
|
38
38
|
}
|
39
39
|
|
40
|
-
async function validateNextAuth(
|
40
|
+
async function validateNextAuth(identityField, identity, protectIdentities, itemAPI) {
|
41
41
|
const match = await findMatchingIdentity(identityField, identity, itemAPI);
|
42
42
|
const {
|
43
43
|
item
|
@@ -87,9 +87,11 @@ function NextAuthPage(props) {
|
|
87
87
|
identity = user.id;
|
88
88
|
} else if (typeof user.id === 'number') {
|
89
89
|
identity = user.id;
|
90
|
+
} else {
|
91
|
+
identity = 0;
|
90
92
|
}
|
91
93
|
|
92
|
-
const result = await validateNextAuth(
|
94
|
+
const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
|
93
95
|
const data = {}; // eslint-disable-next-line no-restricted-syntax
|
94
96
|
|
95
97
|
for (const key in userMap) {
|
@@ -114,11 +116,11 @@ function NextAuthPage(props) {
|
|
114
116
|
|
115
117
|
if (!result.success) {
|
116
118
|
if (!autoCreate) {
|
117
|
-
console.log('
|
119
|
+
console.log('`autoCreate` if set to `false`, skipping user auto-creation');
|
118
120
|
return false;
|
119
121
|
}
|
120
122
|
|
121
|
-
console.log('
|
123
|
+
console.log('`autoCreate` if set to `true`, auto-creating a new user');
|
122
124
|
const createUser = await list.createOne({
|
123
125
|
data
|
124
126
|
}).then(returned => {
|
@@ -130,10 +132,10 @@ function NextAuthPage(props) {
|
|
130
132
|
});
|
131
133
|
console.log('Created User', createUser);
|
132
134
|
return createUser;
|
133
|
-
}
|
134
|
-
|
135
|
-
|
136
|
-
|
135
|
+
} // await list.updateOne({where: {id: result.item.id}, data});
|
136
|
+
|
137
|
+
|
138
|
+
return result.success;
|
137
139
|
},
|
138
140
|
|
139
141
|
async redirect({
|
@@ -162,7 +164,7 @@ function NextAuthPage(props) {
|
|
162
164
|
const identity = token.sub;
|
163
165
|
|
164
166
|
if (!token.itemId) {
|
165
|
-
const result = await validateNextAuth(
|
167
|
+
const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
|
166
168
|
|
167
169
|
if (!result.success) {
|
168
170
|
return;
|
@@ -28,7 +28,7 @@ async function findMatchingIdentity(identityField, identity, queryAPI) {
|
|
28
28
|
};
|
29
29
|
}
|
30
30
|
|
31
|
-
async function validateNextAuth(
|
31
|
+
async function validateNextAuth(identityField, identity, protectIdentities, itemAPI) {
|
32
32
|
const match = await findMatchingIdentity(identityField, identity, itemAPI);
|
33
33
|
const {
|
34
34
|
item
|
@@ -78,9 +78,11 @@ function NextAuthPage(props) {
|
|
78
78
|
identity = user.id;
|
79
79
|
} else if (typeof user.id === 'number') {
|
80
80
|
identity = user.id;
|
81
|
+
} else {
|
82
|
+
identity = 0;
|
81
83
|
}
|
82
84
|
|
83
|
-
const result = await validateNextAuth(
|
85
|
+
const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
|
84
86
|
const data = {}; // eslint-disable-next-line no-restricted-syntax
|
85
87
|
|
86
88
|
for (const key in userMap) {
|
@@ -105,11 +107,11 @@ function NextAuthPage(props) {
|
|
105
107
|
|
106
108
|
if (!result.success) {
|
107
109
|
if (!autoCreate) {
|
108
|
-
console.log('
|
110
|
+
console.log('`autoCreate` if set to `false`, skipping user auto-creation');
|
109
111
|
return false;
|
110
112
|
}
|
111
113
|
|
112
|
-
console.log('
|
114
|
+
console.log('`autoCreate` if set to `true`, auto-creating a new user');
|
113
115
|
const createUser = await list.createOne({
|
114
116
|
data
|
115
117
|
}).then(returned => {
|
@@ -121,10 +123,10 @@ function NextAuthPage(props) {
|
|
121
123
|
});
|
122
124
|
console.log('Created User', createUser);
|
123
125
|
return createUser;
|
124
|
-
}
|
125
|
-
|
126
|
-
|
127
|
-
|
126
|
+
} // await list.updateOne({where: {id: result.item.id}, data});
|
127
|
+
|
128
|
+
|
129
|
+
return result.success;
|
128
130
|
},
|
129
131
|
|
130
132
|
async redirect({
|
@@ -153,7 +155,7 @@ function NextAuthPage(props) {
|
|
153
155
|
const identity = token.sub;
|
154
156
|
|
155
157
|
if (!token.itemId) {
|
156
|
-
const result = await validateNextAuth(
|
158
|
+
const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
|
157
159
|
|
158
160
|
if (!result.success) {
|
159
161
|
return;
|
package/src/index.ts
CHANGED
@@ -292,6 +292,10 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
|
|
292
292
|
lists: {
|
293
293
|
...keystoneConfig.lists,
|
294
294
|
},
|
295
|
+
experimental: {
|
296
|
+
...keystoneConfig.experimental,
|
297
|
+
generateNodeAPI: true,
|
298
|
+
},
|
295
299
|
extendGraphqlSchema: existingExtendGraphQLSchema
|
296
300
|
? (schema) => existingExtendGraphQLSchema(extendGraphqlSchema(schema))
|
297
301
|
: extendGraphqlSchema,
|
@@ -45,15 +45,16 @@ export default function NextAuthPage(props: NextAuthPageProps) {
|
|
45
45
|
identity = user.id;
|
46
46
|
} else if (typeof user.id === 'number') {
|
47
47
|
identity = user.id;
|
48
|
+
} else {
|
49
|
+
identity = 0;
|
48
50
|
}
|
49
51
|
const result = await validateNextAuth(
|
50
|
-
list,
|
51
52
|
identityField,
|
52
53
|
identity,
|
53
54
|
protectIdentities,
|
54
55
|
queryAPI
|
55
56
|
);
|
56
|
-
const data = {};
|
57
|
+
const data: any = {};
|
57
58
|
// eslint-disable-next-line no-restricted-syntax
|
58
59
|
for (const key in userMap) {
|
59
60
|
if (Object.prototype.hasOwnProperty.call(userMap, key)) {
|
@@ -75,12 +76,16 @@ export default function NextAuthPage(props: NextAuthPageProps) {
|
|
75
76
|
|
76
77
|
if (!result.success) {
|
77
78
|
if (!autoCreate) {
|
78
|
-
console.log(
|
79
|
+
console.log(
|
80
|
+
'`autoCreate` if set to `false`, skipping user auto-creation'
|
81
|
+
);
|
79
82
|
return false;
|
80
83
|
}
|
81
|
-
console.log(
|
84
|
+
console.log(
|
85
|
+
'`autoCreate` if set to `true`, auto-creating a new user'
|
86
|
+
);
|
82
87
|
|
83
|
-
const createUser =await list
|
88
|
+
const createUser = await list
|
84
89
|
.createOne({ data })
|
85
90
|
.then((returned) => {
|
86
91
|
console.log('User Created', JSON.stringify(returned));
|
@@ -90,13 +95,11 @@ export default function NextAuthPage(props: NextAuthPageProps) {
|
|
90
95
|
console.log(error);
|
91
96
|
throw new Error(error);
|
92
97
|
});
|
93
|
-
|
94
|
-
|
95
|
-
} else {
|
96
|
-
// await list.updateOne({where: {id: result.item.id}, data});
|
97
|
-
return result.success;
|
98
|
+
console.log('Created User', createUser);
|
99
|
+
return createUser;
|
98
100
|
}
|
99
|
-
|
101
|
+
// await list.updateOne({where: {id: result.item.id}, data});
|
102
|
+
return result.success;
|
100
103
|
},
|
101
104
|
async redirect({ url }) {
|
102
105
|
return url;
|
@@ -112,10 +115,9 @@ export default function NextAuthPage(props: NextAuthPageProps) {
|
|
112
115
|
return returnSession;
|
113
116
|
},
|
114
117
|
async jwt({ token }) {
|
115
|
-
const identity = token.sub;
|
118
|
+
const identity = token.sub as number | string;
|
116
119
|
if (!token.itemId) {
|
117
120
|
const result = await validateNextAuth(
|
118
|
-
list,
|
119
121
|
identityField,
|
120
122
|
identity,
|
121
123
|
protectIdentities,
|
package/src/types.ts
CHANGED
@@ -12,7 +12,7 @@ export type AuthGqlNames = {
|
|
12
12
|
|
13
13
|
export type NextAuthSession = { listKey: string; itemId: string; data: any };
|
14
14
|
|
15
|
-
export type NextAuthProviders = [
|
15
|
+
export type NextAuthProviders = Provider[];
|
16
16
|
|
17
17
|
type KeytoneAuthProviders = {
|
18
18
|
providers: NextAuthProviders;
|