@opensaas/keystone-nextjs-auth 20.5.0 → 21.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +20 -0
- package/README.md +5 -3
- package/dist/declarations/src/gql/getBaseAuthSchema.d.ts +1 -3
- package/dist/declarations/src/index.d.ts +5 -5
- package/dist/declarations/src/pages/NextAuthPage.d.ts +16 -9
- package/dist/declarations/src/schema.d.ts +1 -3
- package/dist/declarations/src/templates/auth.d.ts +4 -12
- package/dist/declarations/src/types.d.ts +17 -20
- package/dist/opensaas-keystone-nextjs-auth.cjs.dev.js +77 -92
- package/dist/opensaas-keystone-nextjs-auth.cjs.prod.js +75 -92
- package/dist/opensaas-keystone-nextjs-auth.esm.js +77 -92
- package/package.json +8 -7
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.dev.js +37 -32
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.prod.js +37 -32
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.esm.js +37 -32
- package/src/gql/getBaseAuthSchema.ts +0 -4
- package/src/index.ts +96 -94
- package/src/pages/NextAuthPage.tsx +59 -38
- package/src/schema.ts +0 -22
- package/src/templates/auth.ts +11 -28
- package/src/templates/next-config.ts +3 -0
- package/src/types.ts +20 -21
- package/src/gql/getInitFirstItemSchema.ts +0 -81
@@ -10,7 +10,6 @@ import { getToken } from 'next-auth/jwt';
|
|
10
10
|
import * as cookie from 'cookie';
|
11
11
|
import ejs from 'ejs';
|
12
12
|
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
13
|
-
import { assertInputObjectType, GraphQLString, GraphQLID } from 'graphql';
|
14
13
|
import { graphql } from '@keystone-6/core';
|
15
14
|
|
16
15
|
const template$1 = `
|
@@ -22,6 +21,9 @@ module.exports = withPreconstruct({
|
|
22
21
|
typescript: {
|
23
22
|
ignoreBuildErrors: true,
|
24
23
|
},
|
24
|
+
env: {
|
25
|
+
NEXTAUTH_URL: process.env.NEXTAUTH_URL || 'http://localhost:<%= process.env.PORT || 3000 %><%= keystonePath || '' %>/api/auth',
|
26
|
+
},
|
25
27
|
eslint: {
|
26
28
|
ignoreDuringBuilds: true,
|
27
29
|
},
|
@@ -77,7 +79,6 @@ const nextConfigTemplate = ({
|
|
77
79
|
|
78
80
|
function getBaseAuthSchema({
|
79
81
|
listKey,
|
80
|
-
gqlNames,
|
81
82
|
base
|
82
83
|
}) {
|
83
84
|
const extension = {
|
@@ -117,22 +118,12 @@ function getBaseAuthSchema({
|
|
117
118
|
}
|
118
119
|
|
119
120
|
const getSchemaExtension = ({
|
120
|
-
|
121
|
-
listKey,
|
122
|
-
gqlNames
|
121
|
+
listKey
|
123
122
|
}) => graphql.extend(base => {
|
124
123
|
var _context;
|
125
124
|
|
126
|
-
const uniqueWhereInputType = assertInputObjectType(base.schema.getType(`${listKey}WhereUniqueInput`));
|
127
|
-
const identityFieldOnUniqueWhere = uniqueWhereInputType.getFields()[identityField];
|
128
|
-
|
129
|
-
if ((identityFieldOnUniqueWhere === null || identityFieldOnUniqueWhere === void 0 ? void 0 : identityFieldOnUniqueWhere.type) !== GraphQLString && (identityFieldOnUniqueWhere === null || identityFieldOnUniqueWhere === void 0 ? void 0 : identityFieldOnUniqueWhere.type) !== GraphQLID) {
|
130
|
-
throw new Error(`createAuth was called with an identityField of ${identityField} on the list ${listKey} ` + `but that field doesn't allow being searched uniquely with a String or ID. ` + `You should likely add \`isIndexed: 'unique'\` ` + `to the field at ${listKey}.${identityField}`);
|
131
|
-
}
|
132
|
-
|
133
125
|
const baseSchema = getBaseAuthSchema({
|
134
126
|
listKey,
|
135
|
-
gqlNames,
|
136
127
|
base
|
137
128
|
});
|
138
129
|
return _filterInstanceProperty(_context = [baseSchema.extension]).call(_context, x => x !== undefined);
|
@@ -144,38 +135,29 @@ import { query } from '.keystone/api';
|
|
144
135
|
import keystoneConfig from '../../../../../keystone';
|
145
136
|
|
146
137
|
export default getNextAuthPage({
|
138
|
+
autoCreate: <%= autoCreate %>,
|
147
139
|
identityField: '<%= identityField %>',
|
148
|
-
sessionData: '<%= sessionData %>',
|
149
140
|
listKey: '<%= listKey %>',
|
150
|
-
|
151
|
-
accountMap: <%- JSON.stringify(accountMap) %>,
|
152
|
-
profileMap: <%- JSON.stringify(profileMap) %>,
|
153
|
-
autoCreate: <%= autoCreate %>,
|
154
|
-
sessionSecret: '<%= sessionSecret %>',
|
141
|
+
pages: keystoneConfig.pages,
|
155
142
|
providers: keystoneConfig.providers,
|
156
143
|
query,
|
144
|
+
resolver: keystoneConfig.resolver,
|
145
|
+
sessionData: '<%= sessionData %>',
|
146
|
+
sessionSecret: '<%= sessionSecret %>',
|
157
147
|
});
|
158
148
|
`;
|
159
149
|
const authTemplate = ({
|
160
|
-
|
150
|
+
autoCreate,
|
161
151
|
identityField,
|
162
|
-
sessionData,
|
163
152
|
listKey,
|
164
|
-
|
165
|
-
userMap,
|
166
|
-
accountMap,
|
167
|
-
profileMap,
|
153
|
+
sessionData,
|
168
154
|
sessionSecret
|
169
155
|
}) => {
|
170
156
|
const authOut = ejs.render(template, {
|
171
|
-
gqlNames,
|
172
157
|
identityField,
|
173
158
|
sessionData,
|
174
159
|
listKey,
|
175
160
|
autoCreate,
|
176
|
-
userMap,
|
177
|
-
accountMap,
|
178
|
-
profileMap,
|
179
161
|
sessionSecret
|
180
162
|
});
|
181
163
|
return authOut;
|
@@ -189,32 +171,22 @@ const _excluded = ["get", "start"];
|
|
189
171
|
*/
|
190
172
|
|
191
173
|
function createAuth({
|
192
|
-
listKey,
|
193
|
-
identityField,
|
194
|
-
sessionData,
|
195
174
|
autoCreate,
|
196
|
-
|
197
|
-
|
198
|
-
|
175
|
+
cookies,
|
176
|
+
identityField,
|
177
|
+
listKey,
|
199
178
|
keystonePath,
|
179
|
+
pages,
|
180
|
+
resolver,
|
200
181
|
providers,
|
182
|
+
sessionData,
|
201
183
|
sessionSecret
|
202
184
|
}) {
|
203
185
|
// The protectIdentities flag is currently under review to see whether it should be
|
204
186
|
// part of the createAuth API (in which case its use cases need to be documented and tested)
|
205
187
|
// or whether always being true is what we want, in which case we can refactor our code
|
206
188
|
// to match this. -TL
|
207
|
-
const
|
208
|
-
// Core
|
209
|
-
authenticateItemWithPassword: `authenticate${listKey}WithPassword`,
|
210
|
-
ItemAuthenticationWithPasswordResult: `${listKey}AuthenticationWithPasswordResult`,
|
211
|
-
ItemAuthenticationWithPasswordSuccess: `${listKey}AuthenticationWithPasswordSuccess`,
|
212
|
-
ItemAuthenticationWithPasswordFailure: `${listKey}AuthenticationWithPasswordFailure`,
|
213
|
-
// Initial data
|
214
|
-
CreateInitialInput: `CreateInitial${listKey}Input`,
|
215
|
-
createInitialItem: `createInitial${listKey}`
|
216
|
-
};
|
217
|
-
const customPath = !keystonePath || keystonePath === '/' ? '' : keystonePath;
|
189
|
+
const customPath = !keystonePath || keystonePath === "/" ? "" : keystonePath;
|
218
190
|
/**
|
219
191
|
* pageMiddleware
|
220
192
|
*
|
@@ -236,21 +208,17 @@ function createAuth({
|
|
236
208
|
} = context;
|
237
209
|
const pathname = url.parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
238
210
|
|
239
|
-
if (pathname === `${customPath}/api/__keystone_api_build`) {
|
240
|
-
return;
|
241
|
-
}
|
242
|
-
|
243
211
|
if (isValidSession) {
|
244
212
|
if (pathname === `${customPath}/api/auth/signin`) {
|
245
213
|
return {
|
246
|
-
kind:
|
214
|
+
kind: "redirect",
|
247
215
|
to: `${customPath}`
|
248
216
|
};
|
249
217
|
}
|
250
218
|
|
251
|
-
if (customPath !==
|
219
|
+
if (customPath !== "" && pathname === "/") {
|
252
220
|
return {
|
253
|
-
kind:
|
221
|
+
kind: "redirect",
|
254
222
|
to: `${customPath}`
|
255
223
|
};
|
256
224
|
}
|
@@ -258,10 +226,14 @@ function createAuth({
|
|
258
226
|
return;
|
259
227
|
}
|
260
228
|
|
229
|
+
if (_includesInstanceProperty(pathname).call(pathname, "/_next/") || _includesInstanceProperty(pathname).call(pathname, "/api/auth/") || _includesInstanceProperty(pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.signIn) || _includesInstanceProperty(pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.error) || _includesInstanceProperty(pathname).call(pathname, pages === null || pages === void 0 ? void 0 : pages.signOut)) {
|
230
|
+
return;
|
231
|
+
}
|
232
|
+
|
261
233
|
if (!session && !_includesInstanceProperty(pathname).call(pathname, `${customPath}/api/auth/`)) {
|
262
234
|
return {
|
263
|
-
kind:
|
264
|
-
to: `${customPath}/api/auth/signin`
|
235
|
+
kind: "redirect",
|
236
|
+
to: (pages === null || pages === void 0 ? void 0 : pages.signIn) || `${customPath}/api/auth/signin`
|
265
237
|
};
|
266
238
|
}
|
267
239
|
};
|
@@ -277,22 +249,18 @@ function createAuth({
|
|
277
249
|
|
278
250
|
const getAdditionalFiles = () => {
|
279
251
|
const filesToWrite = [{
|
280
|
-
mode:
|
281
|
-
outputPath:
|
252
|
+
mode: "write",
|
253
|
+
outputPath: "pages/api/auth/[...nextauth].js",
|
282
254
|
src: authTemplate({
|
283
|
-
|
255
|
+
autoCreate,
|
284
256
|
identityField,
|
285
|
-
sessionData,
|
286
257
|
listKey,
|
287
|
-
|
288
|
-
userMap,
|
289
|
-
accountMap,
|
290
|
-
profileMap,
|
258
|
+
sessionData,
|
291
259
|
sessionSecret
|
292
260
|
})
|
293
261
|
}, {
|
294
|
-
mode:
|
295
|
-
outputPath:
|
262
|
+
mode: "write",
|
263
|
+
outputPath: "next.config.js",
|
296
264
|
src: nextConfigTemplate({
|
297
265
|
keystonePath: customPath
|
298
266
|
})
|
@@ -306,7 +274,8 @@ function createAuth({
|
|
306
274
|
*/
|
307
275
|
|
308
276
|
|
309
|
-
const publicPages = [`${customPath}/api/auth/csrf`, `${customPath}/api/auth/signin`, `${customPath}/api/auth/callback`, `${customPath}/api/auth/session`, `${customPath}/api/auth/providers`, `${customPath}/api/auth/signout`];
|
277
|
+
const publicPages = [`${customPath}/api/__keystone_api_build`, `${customPath}/api/auth/csrf`, `${customPath}/api/auth/signin`, `${customPath}/api/auth/callback`, `${customPath}/api/auth/session`, `${customPath}/api/auth/providers`, `${customPath}/api/auth/signout`, `${customPath}/api/auth/error`]; // TODO: Add Provider Types
|
278
|
+
// @ts-ignore
|
310
279
|
|
311
280
|
function addPages(provider) {
|
312
281
|
const name = provider.id;
|
@@ -324,8 +293,7 @@ function createAuth({
|
|
324
293
|
|
325
294
|
const extendGraphqlSchema = getSchemaExtension({
|
326
295
|
identityField,
|
327
|
-
listKey
|
328
|
-
gqlNames
|
296
|
+
listKey
|
329
297
|
});
|
330
298
|
/**
|
331
299
|
* validateConfig
|
@@ -339,7 +307,9 @@ function createAuth({
|
|
339
307
|
if (listConfig === undefined) {
|
340
308
|
const msg = `A createAuth() invocation specifies the list "${listKey}" but no list with that key has been defined.`;
|
341
309
|
throw new Error(msg);
|
342
|
-
} // TODO: Check
|
310
|
+
} // TODO: Check if providers
|
311
|
+
// TODO: Check other required commands/data
|
312
|
+
// TODO: Check for String-like typing for identityField? How?
|
343
313
|
// TODO: Validate that the identifyField is unique.
|
344
314
|
// TODO: If this field isn't required, what happens if I try to log in as `null`?
|
345
315
|
|
@@ -347,9 +317,9 @@ function createAuth({
|
|
347
317
|
const identityFieldConfig = listConfig.fields[identityField];
|
348
318
|
|
349
319
|
if (identityFieldConfig === undefined) {
|
350
|
-
const
|
320
|
+
const identityFieldName = _JSON$stringify(identityField);
|
351
321
|
|
352
|
-
const msg = `A createAuth() invocation for the "${listKey}" list specifies ${
|
322
|
+
const msg = `A createAuth() invocation for the "${listKey}" list specifies ${identityFieldName} as its identityField but no field with that key exists on the list.`;
|
353
323
|
throw new Error(msg);
|
354
324
|
}
|
355
325
|
};
|
@@ -372,7 +342,15 @@ function createAuth({
|
|
372
342
|
sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
|
373
343
|
|
374
344
|
return _objectSpread(_objectSpread({}, sessionStrategy), {}, {
|
375
|
-
start
|
345
|
+
start: async ({
|
346
|
+
res
|
347
|
+
}) => {
|
348
|
+
console.log("start");
|
349
|
+
const session = await start({
|
350
|
+
res
|
351
|
+
});
|
352
|
+
return session;
|
353
|
+
},
|
376
354
|
get: async ({
|
377
355
|
req
|
378
356
|
}) => {
|
@@ -380,16 +358,15 @@ function createAuth({
|
|
380
358
|
|
381
359
|
const pathname = url.parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
382
360
|
|
383
|
-
if (_includesInstanceProperty(pathname).call(pathname,
|
361
|
+
if (_includesInstanceProperty(pathname).call(pathname, "/api/auth")) {
|
384
362
|
return;
|
385
363
|
}
|
386
364
|
|
387
|
-
if (((_req$headers$authoriz = req.headers.authorization) === null || _req$headers$authoriz === void 0 ? void 0 : _req$headers$authoriz.split(
|
365
|
+
if (((_req$headers$authoriz = req.headers.authorization) === null || _req$headers$authoriz === void 0 ? void 0 : _req$headers$authoriz.split(" ")[0]) === "Bearer") {
|
388
366
|
var _token$data;
|
389
367
|
|
390
|
-
const request = req;
|
391
368
|
const token = await getToken({
|
392
|
-
req
|
369
|
+
req,
|
393
370
|
secret: sessionSecret
|
394
371
|
});
|
395
372
|
|
@@ -410,14 +387,15 @@ function createAuth({
|
|
410
387
|
res,
|
411
388
|
req
|
412
389
|
}) => {
|
413
|
-
const TOKEN_NAME = process.env.NODE_ENV ===
|
414
|
-
res.setHeader(
|
390
|
+
const TOKEN_NAME = process.env.NODE_ENV === "production" ? "__Secure-next-auth.session-token" : "next-auth.session-token";
|
391
|
+
res.setHeader("Set-Cookie", cookie.serialize(TOKEN_NAME, "", {
|
415
392
|
maxAge: 0,
|
416
393
|
expires: new Date(),
|
417
394
|
httpOnly: true,
|
418
|
-
secure: process.env.NODE_ENV ===
|
419
|
-
path:
|
420
|
-
sameSite:
|
395
|
+
secure: process.env.NODE_ENV === "production",
|
396
|
+
path: "/",
|
397
|
+
sameSite: "lax",
|
398
|
+
// TODO: Update parse to URL
|
421
399
|
domain: url.parse(req.url).hostname
|
422
400
|
}));
|
423
401
|
}
|
@@ -454,30 +432,37 @@ function createAuth({
|
|
454
432
|
},
|
455
433
|
enableSessionItem: true,
|
456
434
|
isAccessAllowed: async context => {
|
457
|
-
var _context$req,
|
435
|
+
var _context$req, _keystoneConfig$ui3;
|
436
|
+
|
437
|
+
const {
|
438
|
+
req
|
439
|
+
} = context;
|
440
|
+
const pathname = url.parse(req === null || req === void 0 ? void 0 : req.url).pathname; // Allow nextjs scripts and static files to be accessed without auth
|
458
441
|
|
459
|
-
if (
|
442
|
+
if (_includesInstanceProperty(pathname).call(pathname, "/_next/")) {
|
460
443
|
return true;
|
461
|
-
} // Allow
|
462
|
-
// even if the user isn't logged in (which should always be the case if they're seeing /init)
|
444
|
+
} // Allow keystone to access /api/__keystone_api_build for hot reloading
|
463
445
|
|
464
446
|
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
return
|
447
|
+
if (process.env.NODE_ENV !== "production" && ((_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.url) !== undefined && new _URL(context.req.url, "http://example.com").pathname === `${customPath}/api/__keystone_api_build`) {
|
448
|
+
return true;
|
449
|
+
}
|
450
|
+
|
451
|
+
return (_keystoneConfig$ui3 = keystoneConfig.ui) !== null && _keystoneConfig$ui3 !== void 0 && _keystoneConfig$ui3.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined;
|
470
452
|
}
|
471
453
|
});
|
472
454
|
}
|
473
455
|
|
474
|
-
if (!keystoneConfig.session) throw new TypeError(
|
456
|
+
if (!keystoneConfig.session) throw new TypeError("Missing .session configuration");
|
475
457
|
const session = withItemData(keystoneConfig.session);
|
476
458
|
const existingExtendGraphQLSchema = keystoneConfig.extendGraphqlSchema;
|
477
459
|
return _objectSpread(_objectSpread({}, keystoneConfig), {}, {
|
478
460
|
ui,
|
479
|
-
|
461
|
+
cookies,
|
480
462
|
providers,
|
463
|
+
pages,
|
464
|
+
resolver,
|
465
|
+
session,
|
481
466
|
lists: _objectSpread({}, keystoneConfig.lists),
|
482
467
|
experimental: _objectSpread(_objectSpread({}, keystoneConfig.experimental), {}, {
|
483
468
|
generateNodeAPI: true
|
package/package.json
CHANGED
@@ -1,27 +1,28 @@
|
|
1
1
|
{
|
2
2
|
"name": "@opensaas/keystone-nextjs-auth",
|
3
|
-
"version": "
|
3
|
+
"version": "21.1.1",
|
4
4
|
"repository": "https://github.com/opensaasau/keystone-nextjs-auth",
|
5
5
|
"license": "MIT",
|
6
6
|
"main": "dist/opensaas-keystone-nextjs-auth.cjs.js",
|
7
7
|
"module": "dist/opensaas-keystone-nextjs-auth.esm.js",
|
8
8
|
"dependencies": {
|
9
|
-
"@babel/runtime": "^7.17.
|
10
|
-
"@babel/runtime-corejs3": "^7.17.
|
9
|
+
"@babel/runtime": "^7.17.9",
|
10
|
+
"@babel/runtime-corejs3": "^7.17.9",
|
11
11
|
"@types/ejs": "^3.1.0",
|
12
|
-
"cookie": "^0.
|
12
|
+
"cookie": "^0.5.0",
|
13
13
|
"cross-fetch": "^3.1.5",
|
14
|
-
"ejs": "^3.1.
|
14
|
+
"ejs": "^3.1.7",
|
15
15
|
"fast-deep-equal": "^3.1.3",
|
16
|
-
"
|
17
|
-
"next-auth": "^4.3.1"
|
16
|
+
"next-auth": "^4.3.4"
|
18
17
|
},
|
19
18
|
"devDependencies": {
|
20
19
|
"@keystone-6/core": "^1.1.0",
|
20
|
+
"next": "12.1.0",
|
21
21
|
"react": "^17.0.2"
|
22
22
|
},
|
23
23
|
"peerDependencies": {
|
24
24
|
"@keystone-6/core": "^1.1.0",
|
25
|
+
"next": "12.1.0",
|
25
26
|
"react": "^17.0.2"
|
26
27
|
},
|
27
28
|
"engines": {
|
@@ -58,23 +58,42 @@ async function validateNextAuth(identityField, identity, protectIdentities, item
|
|
58
58
|
|
59
59
|
function NextAuthPage(props) {
|
60
60
|
const {
|
61
|
+
autoCreate,
|
62
|
+
cookies,
|
63
|
+
events,
|
64
|
+
identityField,
|
65
|
+
jwt,
|
66
|
+
listKey,
|
67
|
+
pages,
|
61
68
|
providers,
|
62
69
|
query,
|
63
|
-
|
70
|
+
resolver,
|
64
71
|
sessionData,
|
65
|
-
listKey,
|
66
|
-
autoCreate,
|
67
|
-
userMap,
|
68
|
-
accountMap,
|
69
|
-
profileMap,
|
70
72
|
sessionSecret
|
71
|
-
} = props;
|
73
|
+
} = props; // TODO: (v1.1). https://github.com/ijsto/keystone-6-oauth/projects/1#card-78602004
|
74
|
+
|
75
|
+
console.log('NextAuthPages... ', pages);
|
76
|
+
|
77
|
+
if (!query) {
|
78
|
+
console.error('NextAuthPage got no query.');
|
79
|
+
return null;
|
80
|
+
}
|
81
|
+
|
82
|
+
if (!providers || !providers.length) {
|
83
|
+
console.error('You need to provide at least one provider.');
|
84
|
+
return null;
|
85
|
+
}
|
86
|
+
|
72
87
|
const list = query[listKey];
|
73
88
|
const queryAPI = query[listKey];
|
74
89
|
const protectIdentities = true;
|
75
90
|
return NextAuth__default["default"]({
|
76
|
-
|
91
|
+
cookies,
|
77
92
|
providers,
|
93
|
+
pages: pages || {},
|
94
|
+
events: events || {},
|
95
|
+
jwt: jwt || {},
|
96
|
+
secret: sessionSecret,
|
78
97
|
callbacks: {
|
79
98
|
async signIn({
|
80
99
|
user,
|
@@ -91,28 +110,16 @@ function NextAuthPage(props) {
|
|
91
110
|
identity = 0;
|
92
111
|
}
|
93
112
|
|
94
|
-
const
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
}
|
101
|
-
} // eslint-disable-next-line no-restricted-syntax
|
102
|
-
|
113
|
+
const userInput = resolver ? await resolver({
|
114
|
+
user,
|
115
|
+
account,
|
116
|
+
profile
|
117
|
+
}) : {};
|
118
|
+
const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI); // ID
|
103
119
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
}
|
108
|
-
} // eslint-disable-next-line no-restricted-syntax
|
109
|
-
|
110
|
-
|
111
|
-
for (const key in profileMap) {
|
112
|
-
if (Object.prototype.hasOwnProperty.call(profileMap, key)) {
|
113
|
-
data[key] = profile[profileMap[key]];
|
114
|
-
}
|
115
|
-
}
|
120
|
+
const data = _objectSpread({
|
121
|
+
[identityField]: identity
|
122
|
+
}, userInput);
|
116
123
|
|
117
124
|
if (!result.success) {
|
118
125
|
if (!autoCreate) {
|
@@ -167,9 +174,7 @@ function NextAuthPage(props) {
|
|
167
174
|
const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
|
168
175
|
|
169
176
|
if (!result.success) {
|
170
|
-
return
|
171
|
-
result: false
|
172
|
-
};
|
177
|
+
return token;
|
173
178
|
}
|
174
179
|
|
175
180
|
token.itemId = result.item.id;
|
package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.prod.js
CHANGED
@@ -58,23 +58,42 @@ async function validateNextAuth(identityField, identity, protectIdentities, item
|
|
58
58
|
|
59
59
|
function NextAuthPage(props) {
|
60
60
|
const {
|
61
|
+
autoCreate,
|
62
|
+
cookies,
|
63
|
+
events,
|
64
|
+
identityField,
|
65
|
+
jwt,
|
66
|
+
listKey,
|
67
|
+
pages,
|
61
68
|
providers,
|
62
69
|
query,
|
63
|
-
|
70
|
+
resolver,
|
64
71
|
sessionData,
|
65
|
-
listKey,
|
66
|
-
autoCreate,
|
67
|
-
userMap,
|
68
|
-
accountMap,
|
69
|
-
profileMap,
|
70
72
|
sessionSecret
|
71
|
-
} = props;
|
73
|
+
} = props; // TODO: (v1.1). https://github.com/ijsto/keystone-6-oauth/projects/1#card-78602004
|
74
|
+
|
75
|
+
console.log('NextAuthPages... ', pages);
|
76
|
+
|
77
|
+
if (!query) {
|
78
|
+
console.error('NextAuthPage got no query.');
|
79
|
+
return null;
|
80
|
+
}
|
81
|
+
|
82
|
+
if (!providers || !providers.length) {
|
83
|
+
console.error('You need to provide at least one provider.');
|
84
|
+
return null;
|
85
|
+
}
|
86
|
+
|
72
87
|
const list = query[listKey];
|
73
88
|
const queryAPI = query[listKey];
|
74
89
|
const protectIdentities = true;
|
75
90
|
return NextAuth__default["default"]({
|
76
|
-
|
91
|
+
cookies,
|
77
92
|
providers,
|
93
|
+
pages: pages || {},
|
94
|
+
events: events || {},
|
95
|
+
jwt: jwt || {},
|
96
|
+
secret: sessionSecret,
|
78
97
|
callbacks: {
|
79
98
|
async signIn({
|
80
99
|
user,
|
@@ -91,28 +110,16 @@ function NextAuthPage(props) {
|
|
91
110
|
identity = 0;
|
92
111
|
}
|
93
112
|
|
94
|
-
const
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
}
|
101
|
-
} // eslint-disable-next-line no-restricted-syntax
|
102
|
-
|
113
|
+
const userInput = resolver ? await resolver({
|
114
|
+
user,
|
115
|
+
account,
|
116
|
+
profile
|
117
|
+
}) : {};
|
118
|
+
const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI); // ID
|
103
119
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
}
|
108
|
-
} // eslint-disable-next-line no-restricted-syntax
|
109
|
-
|
110
|
-
|
111
|
-
for (const key in profileMap) {
|
112
|
-
if (Object.prototype.hasOwnProperty.call(profileMap, key)) {
|
113
|
-
data[key] = profile[profileMap[key]];
|
114
|
-
}
|
115
|
-
}
|
120
|
+
const data = _objectSpread({
|
121
|
+
[identityField]: identity
|
122
|
+
}, userInput);
|
116
123
|
|
117
124
|
if (!result.success) {
|
118
125
|
if (!autoCreate) {
|
@@ -167,9 +174,7 @@ function NextAuthPage(props) {
|
|
167
174
|
const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
|
168
175
|
|
169
176
|
if (!result.success) {
|
170
|
-
return
|
171
|
-
result: false
|
172
|
-
};
|
177
|
+
return token;
|
173
178
|
}
|
174
179
|
|
175
180
|
token.itemId = result.item.id;
|