@opensaas/keystone-nextjs-auth 24.0.0 → 25.0.0-rc-1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +12 -0
- package/dist/declarations/src/gql/getBaseAuthSchema.d.ts +1 -1
- package/dist/opensaas-keystone-nextjs-auth.cjs.dev.js +67 -59
- package/dist/opensaas-keystone-nextjs-auth.cjs.prod.js +67 -59
- package/dist/opensaas-keystone-nextjs-auth.esm.js +67 -59
- package/package.json +6 -9
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.dev.js +19 -15
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.prod.js +19 -15
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.esm.js +19 -15
- package/src/index.ts +0 -5
- package/src/templates/auth.ejs +16 -12
- package/src/templates/auth.ts +3 -3
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# @opensaas-keystone/nextjs-auth
|
2
2
|
|
3
|
+
## 24.1.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- ae15a2c: Update dependency @keystone-6/core to ^2.2.0
|
8
|
+
- b730bff: Update react monorepo (minor)
|
9
|
+
|
10
|
+
### Patch Changes
|
11
|
+
|
12
|
+
- 0a7d339: Update patch dependencies (patch)
|
13
|
+
- 7d40c8b: Fix keystone `onConnect` running on next-auth initialisation
|
14
|
+
|
3
15
|
## 24.0.0
|
4
16
|
|
5
17
|
### Major Changes
|
@@ -6,7 +6,7 @@ export declare function getBaseAuthSchema({ listKey, base, }: {
|
|
6
6
|
}): {
|
7
7
|
extension: {
|
8
8
|
query: {
|
9
|
-
authenticatedItem: import("@graphql-ts/schema").Field<unknown, {}, import("@graphql-ts/schema").UnionType<BaseItem, graphql.Context>, string,
|
9
|
+
authenticatedItem: import("@graphql-ts/schema").Field<unknown, {}, import("@graphql-ts/schema").UnionType<BaseItem, graphql.Context>, string, import("@keystone-6/core/types").KeystoneContext<import("@keystone-6/core/types").BaseKeystoneTypeInfo>>;
|
10
10
|
};
|
11
11
|
};
|
12
12
|
};
|
@@ -101,19 +101,21 @@ module.exports = withPreconstruct({
|
|
101
101
|
<% } %>
|
102
102
|
});
|
103
103
|
`;
|
104
|
-
const nextConfigTemplate =
|
105
|
-
|
106
|
-
|
104
|
+
const nextConfigTemplate = _ref => {
|
105
|
+
let {
|
106
|
+
keystonePath
|
107
|
+
} = _ref;
|
107
108
|
const nextConfigOut = ejs__default["default"].render(template$1, {
|
108
109
|
keystonePath
|
109
110
|
});
|
110
111
|
return nextConfigOut;
|
111
112
|
};
|
112
113
|
|
113
|
-
function getBaseAuthSchema({
|
114
|
-
|
115
|
-
|
116
|
-
|
114
|
+
function getBaseAuthSchema(_ref) {
|
115
|
+
let {
|
116
|
+
listKey,
|
117
|
+
base
|
118
|
+
} = _ref;
|
117
119
|
const extension = {
|
118
120
|
query: {
|
119
121
|
authenticatedItem: core.graphql.field({
|
@@ -127,10 +129,12 @@ function getBaseAuthSchema({
|
|
127
129
|
}
|
128
130
|
}),
|
129
131
|
|
130
|
-
resolve(root, args, {
|
131
|
-
|
132
|
-
|
133
|
-
|
132
|
+
resolve(root, args, _ref2) {
|
133
|
+
let {
|
134
|
+
session,
|
135
|
+
db
|
136
|
+
} = _ref2;
|
137
|
+
|
134
138
|
if (typeof (session === null || session === void 0 ? void 0 : session.itemId) === 'string' && typeof session.listKey === 'string') {
|
135
139
|
return db[session.listKey].findOne({
|
136
140
|
where: {
|
@@ -150,25 +154,28 @@ function getBaseAuthSchema({
|
|
150
154
|
};
|
151
155
|
}
|
152
156
|
|
153
|
-
const getSchemaExtension =
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
+
const getSchemaExtension = _ref => {
|
158
|
+
let {
|
159
|
+
listKey
|
160
|
+
} = _ref;
|
161
|
+
return core.graphql.extend(base => {
|
162
|
+
var _context;
|
157
163
|
|
158
|
-
|
159
|
-
|
160
|
-
|
164
|
+
const baseSchema = getBaseAuthSchema({
|
165
|
+
listKey,
|
166
|
+
base
|
167
|
+
});
|
168
|
+
return _filterInstanceProperty__default["default"](_context = [baseSchema.extension]).call(_context, x => x !== undefined);
|
161
169
|
});
|
162
|
-
|
163
|
-
});
|
170
|
+
};
|
164
171
|
|
165
172
|
const template = `
|
173
|
+
import { getContext } from '@keystone-6/core/context';
|
166
174
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
167
175
|
import keystoneConfig from '../../../../../keystone';
|
168
|
-
import
|
169
|
-
import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
|
176
|
+
import * as PrismaModule from '.prisma/client';
|
170
177
|
|
171
|
-
const keystoneQueryAPI = global.keystoneQueryAPI ||
|
178
|
+
const keystoneQueryAPI = global.keystoneQueryAPI || getContext(keystoneConfig, PrismaModule).sudo().query;
|
172
179
|
|
173
180
|
if (process.env.NODE_ENV !== 'production') globalThis.keystoneQueryAPI = keystoneQueryAPI
|
174
181
|
|
@@ -184,13 +191,14 @@ export default getNextAuthPage({
|
|
184
191
|
sessionSecret: '<%= sessionSecret %>',
|
185
192
|
});
|
186
193
|
`;
|
187
|
-
const authTemplate =
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
+
const authTemplate = _ref => {
|
195
|
+
let {
|
196
|
+
autoCreate,
|
197
|
+
identityField,
|
198
|
+
listKey,
|
199
|
+
sessionData,
|
200
|
+
sessionSecret
|
201
|
+
} = _ref;
|
194
202
|
const authOut = ejs__default["default"].render(template, {
|
195
203
|
identityField,
|
196
204
|
sessionData,
|
@@ -208,18 +216,19 @@ const _excluded = ["get", "end"];
|
|
208
216
|
* Generates config for Keystone to implement standard auth features.
|
209
217
|
*/
|
210
218
|
|
211
|
-
function createAuth({
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
219
|
+
function createAuth(_ref) {
|
220
|
+
let {
|
221
|
+
autoCreate,
|
222
|
+
cookies,
|
223
|
+
identityField,
|
224
|
+
listKey,
|
225
|
+
keystonePath,
|
226
|
+
pages,
|
227
|
+
resolver,
|
228
|
+
providers,
|
229
|
+
sessionData,
|
230
|
+
sessionSecret
|
231
|
+
} = _ref;
|
223
232
|
// The protectIdentities flag is currently under review to see whether it should be
|
224
233
|
// part of the createAuth API (in which case its use cases need to be documented and tested)
|
225
234
|
// or whether always being true is what we want, in which case we can refactor our code
|
@@ -236,10 +245,11 @@ function createAuth({
|
|
236
245
|
* - to the signin page when no valid session is present
|
237
246
|
*/
|
238
247
|
|
239
|
-
const pageMiddleware = async
|
240
|
-
|
241
|
-
|
242
|
-
|
248
|
+
const pageMiddleware = async _ref2 => {
|
249
|
+
let {
|
250
|
+
context,
|
251
|
+
isValidSession
|
252
|
+
} = _ref2;
|
243
253
|
const {
|
244
254
|
req,
|
245
255
|
session
|
@@ -380,12 +390,13 @@ function createAuth({
|
|
380
390
|
sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
|
381
391
|
|
382
392
|
return _objectSpread(_objectSpread({}, sessionStrategy), {}, {
|
383
|
-
get: async
|
384
|
-
req,
|
385
|
-
createContext
|
386
|
-
}) => {
|
393
|
+
get: async _ref3 => {
|
387
394
|
var _req$headers, _req$headers$authoriz;
|
388
395
|
|
396
|
+
let {
|
397
|
+
req,
|
398
|
+
createContext
|
399
|
+
} = _ref3;
|
389
400
|
const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
390
401
|
let nextSession;
|
391
402
|
|
@@ -428,11 +439,12 @@ function createAuth({
|
|
428
439
|
itemId: nextSession.itemId
|
429
440
|
});
|
430
441
|
},
|
431
|
-
end: async
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
442
|
+
end: async _ref4 => {
|
443
|
+
let {
|
444
|
+
res,
|
445
|
+
req,
|
446
|
+
createContext
|
447
|
+
} = _ref4;
|
436
448
|
await end({
|
437
449
|
res,
|
438
450
|
req,
|
@@ -481,7 +493,6 @@ function createAuth({
|
|
481
493
|
|
482
494
|
return (await pageMiddleware(args)) ?? (keystoneConfig === null || keystoneConfig === void 0 ? void 0 : (_keystoneConfig$ui2 = keystoneConfig.ui) === null || _keystoneConfig$ui2 === void 0 ? void 0 : (_keystoneConfig$ui2$p = _keystoneConfig$ui2.pageMiddleware) === null || _keystoneConfig$ui2$p === void 0 ? void 0 : _keystoneConfig$ui2$p.call(_keystoneConfig$ui2, args));
|
483
495
|
},
|
484
|
-
enableSessionItem: true,
|
485
496
|
isAccessAllowed: async context => {
|
486
497
|
var _context$req, _keystoneConfig$ui3;
|
487
498
|
|
@@ -515,9 +526,6 @@ function createAuth({
|
|
515
526
|
resolver,
|
516
527
|
session,
|
517
528
|
lists: _objectSpread({}, keystoneConfig.lists),
|
518
|
-
experimental: _objectSpread(_objectSpread({}, keystoneConfig.experimental), {}, {
|
519
|
-
generateNodeAPI: true
|
520
|
-
}),
|
521
529
|
extendGraphqlSchema: existingExtendGraphQLSchema ? schema => existingExtendGraphQLSchema(extendGraphqlSchema(schema)) : extendGraphqlSchema
|
522
530
|
});
|
523
531
|
};
|
@@ -100,19 +100,21 @@ module.exports = withPreconstruct({
|
|
100
100
|
<% } %>
|
101
101
|
});
|
102
102
|
`;
|
103
|
-
const nextConfigTemplate =
|
104
|
-
|
105
|
-
|
103
|
+
const nextConfigTemplate = _ref => {
|
104
|
+
let {
|
105
|
+
keystonePath
|
106
|
+
} = _ref;
|
106
107
|
const nextConfigOut = ejs__default["default"].render(template$1, {
|
107
108
|
keystonePath
|
108
109
|
});
|
109
110
|
return nextConfigOut;
|
110
111
|
};
|
111
112
|
|
112
|
-
function getBaseAuthSchema({
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
function getBaseAuthSchema(_ref) {
|
114
|
+
let {
|
115
|
+
listKey,
|
116
|
+
base
|
117
|
+
} = _ref;
|
116
118
|
const extension = {
|
117
119
|
query: {
|
118
120
|
authenticatedItem: core.graphql.field({
|
@@ -126,10 +128,12 @@ function getBaseAuthSchema({
|
|
126
128
|
}
|
127
129
|
}),
|
128
130
|
|
129
|
-
resolve(root, args, {
|
130
|
-
|
131
|
-
|
132
|
-
|
131
|
+
resolve(root, args, _ref2) {
|
132
|
+
let {
|
133
|
+
session,
|
134
|
+
db
|
135
|
+
} = _ref2;
|
136
|
+
|
133
137
|
if (typeof (session === null || session === void 0 ? void 0 : session.itemId) === 'string' && typeof session.listKey === 'string') {
|
134
138
|
return db[session.listKey].findOne({
|
135
139
|
where: {
|
@@ -149,25 +153,28 @@ function getBaseAuthSchema({
|
|
149
153
|
};
|
150
154
|
}
|
151
155
|
|
152
|
-
const getSchemaExtension =
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
+
const getSchemaExtension = _ref => {
|
157
|
+
let {
|
158
|
+
listKey
|
159
|
+
} = _ref;
|
160
|
+
return core.graphql.extend(base => {
|
161
|
+
var _context;
|
156
162
|
|
157
|
-
|
158
|
-
|
159
|
-
|
163
|
+
const baseSchema = getBaseAuthSchema({
|
164
|
+
listKey,
|
165
|
+
base
|
166
|
+
});
|
167
|
+
return _filterInstanceProperty__default["default"](_context = [baseSchema.extension]).call(_context, x => x !== undefined);
|
160
168
|
});
|
161
|
-
|
162
|
-
});
|
169
|
+
};
|
163
170
|
|
164
171
|
const template = `
|
172
|
+
import { getContext } from '@keystone-6/core/context';
|
165
173
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
166
174
|
import keystoneConfig from '../../../../../keystone';
|
167
|
-
import
|
168
|
-
import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
|
175
|
+
import * as PrismaModule from '.prisma/client';
|
169
176
|
|
170
|
-
const keystoneQueryAPI = global.keystoneQueryAPI ||
|
177
|
+
const keystoneQueryAPI = global.keystoneQueryAPI || getContext(keystoneConfig, PrismaModule).sudo().query;
|
171
178
|
|
172
179
|
if (process.env.NODE_ENV !== 'production') globalThis.keystoneQueryAPI = keystoneQueryAPI
|
173
180
|
|
@@ -183,13 +190,14 @@ export default getNextAuthPage({
|
|
183
190
|
sessionSecret: '<%= sessionSecret %>',
|
184
191
|
});
|
185
192
|
`;
|
186
|
-
const authTemplate =
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
+
const authTemplate = _ref => {
|
194
|
+
let {
|
195
|
+
autoCreate,
|
196
|
+
identityField,
|
197
|
+
listKey,
|
198
|
+
sessionData,
|
199
|
+
sessionSecret
|
200
|
+
} = _ref;
|
193
201
|
const authOut = ejs__default["default"].render(template, {
|
194
202
|
identityField,
|
195
203
|
sessionData,
|
@@ -207,18 +215,19 @@ const _excluded = ["get", "end"];
|
|
207
215
|
* Generates config for Keystone to implement standard auth features.
|
208
216
|
*/
|
209
217
|
|
210
|
-
function createAuth({
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
218
|
+
function createAuth(_ref) {
|
219
|
+
let {
|
220
|
+
autoCreate,
|
221
|
+
cookies,
|
222
|
+
identityField,
|
223
|
+
listKey,
|
224
|
+
keystonePath,
|
225
|
+
pages,
|
226
|
+
resolver,
|
227
|
+
providers,
|
228
|
+
sessionData,
|
229
|
+
sessionSecret
|
230
|
+
} = _ref;
|
222
231
|
// The protectIdentities flag is currently under review to see whether it should be
|
223
232
|
// part of the createAuth API (in which case its use cases need to be documented and tested)
|
224
233
|
// or whether always being true is what we want, in which case we can refactor our code
|
@@ -235,10 +244,11 @@ function createAuth({
|
|
235
244
|
* - to the signin page when no valid session is present
|
236
245
|
*/
|
237
246
|
|
238
|
-
const pageMiddleware = async
|
239
|
-
|
240
|
-
|
241
|
-
|
247
|
+
const pageMiddleware = async _ref2 => {
|
248
|
+
let {
|
249
|
+
context,
|
250
|
+
isValidSession
|
251
|
+
} = _ref2;
|
242
252
|
const {
|
243
253
|
req,
|
244
254
|
session
|
@@ -379,12 +389,13 @@ function createAuth({
|
|
379
389
|
sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
|
380
390
|
|
381
391
|
return _objectSpread(_objectSpread({}, sessionStrategy), {}, {
|
382
|
-
get: async
|
383
|
-
req,
|
384
|
-
createContext
|
385
|
-
}) => {
|
392
|
+
get: async _ref3 => {
|
386
393
|
var _req$headers, _req$headers$authoriz;
|
387
394
|
|
395
|
+
let {
|
396
|
+
req,
|
397
|
+
createContext
|
398
|
+
} = _ref3;
|
388
399
|
const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
389
400
|
let nextSession;
|
390
401
|
|
@@ -427,11 +438,12 @@ function createAuth({
|
|
427
438
|
itemId: nextSession.itemId
|
428
439
|
});
|
429
440
|
},
|
430
|
-
end: async
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
441
|
+
end: async _ref4 => {
|
442
|
+
let {
|
443
|
+
res,
|
444
|
+
req,
|
445
|
+
createContext
|
446
|
+
} = _ref4;
|
435
447
|
await end({
|
436
448
|
res,
|
437
449
|
req,
|
@@ -480,7 +492,6 @@ function createAuth({
|
|
480
492
|
|
481
493
|
return (await pageMiddleware(args)) ?? (keystoneConfig === null || keystoneConfig === void 0 ? void 0 : (_keystoneConfig$ui2 = keystoneConfig.ui) === null || _keystoneConfig$ui2 === void 0 ? void 0 : (_keystoneConfig$ui2$p = _keystoneConfig$ui2.pageMiddleware) === null || _keystoneConfig$ui2$p === void 0 ? void 0 : _keystoneConfig$ui2$p.call(_keystoneConfig$ui2, args));
|
482
494
|
},
|
483
|
-
enableSessionItem: true,
|
484
495
|
isAccessAllowed: async context => {
|
485
496
|
var _keystoneConfig$ui3;
|
486
497
|
|
@@ -509,9 +520,6 @@ function createAuth({
|
|
509
520
|
resolver,
|
510
521
|
session,
|
511
522
|
lists: _objectSpread({}, keystoneConfig.lists),
|
512
|
-
experimental: _objectSpread(_objectSpread({}, keystoneConfig.experimental), {}, {
|
513
|
-
generateNodeAPI: true
|
514
|
-
}),
|
515
523
|
extendGraphqlSchema: existingExtendGraphQLSchema ? schema => existingExtendGraphQLSchema(extendGraphqlSchema(schema)) : extendGraphqlSchema
|
516
524
|
});
|
517
525
|
};
|
@@ -68,19 +68,21 @@ module.exports = withPreconstruct({
|
|
68
68
|
<% } %>
|
69
69
|
});
|
70
70
|
`;
|
71
|
-
const nextConfigTemplate =
|
72
|
-
|
73
|
-
|
71
|
+
const nextConfigTemplate = _ref => {
|
72
|
+
let {
|
73
|
+
keystonePath
|
74
|
+
} = _ref;
|
74
75
|
const nextConfigOut = ejs.render(template$1, {
|
75
76
|
keystonePath
|
76
77
|
});
|
77
78
|
return nextConfigOut;
|
78
79
|
};
|
79
80
|
|
80
|
-
function getBaseAuthSchema({
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
function getBaseAuthSchema(_ref) {
|
82
|
+
let {
|
83
|
+
listKey,
|
84
|
+
base
|
85
|
+
} = _ref;
|
84
86
|
const extension = {
|
85
87
|
query: {
|
86
88
|
authenticatedItem: graphql.field({
|
@@ -94,10 +96,12 @@ function getBaseAuthSchema({
|
|
94
96
|
}
|
95
97
|
}),
|
96
98
|
|
97
|
-
resolve(root, args, {
|
98
|
-
|
99
|
-
|
100
|
-
|
99
|
+
resolve(root, args, _ref2) {
|
100
|
+
let {
|
101
|
+
session,
|
102
|
+
db
|
103
|
+
} = _ref2;
|
104
|
+
|
101
105
|
if (typeof (session === null || session === void 0 ? void 0 : session.itemId) === 'string' && typeof session.listKey === 'string') {
|
102
106
|
return db[session.listKey].findOne({
|
103
107
|
where: {
|
@@ -117,25 +121,28 @@ function getBaseAuthSchema({
|
|
117
121
|
};
|
118
122
|
}
|
119
123
|
|
120
|
-
const getSchemaExtension =
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
+
const getSchemaExtension = _ref => {
|
125
|
+
let {
|
126
|
+
listKey
|
127
|
+
} = _ref;
|
128
|
+
return graphql.extend(base => {
|
129
|
+
var _context;
|
124
130
|
|
125
|
-
|
126
|
-
|
127
|
-
|
131
|
+
const baseSchema = getBaseAuthSchema({
|
132
|
+
listKey,
|
133
|
+
base
|
134
|
+
});
|
135
|
+
return _filterInstanceProperty(_context = [baseSchema.extension]).call(_context, x => x !== undefined);
|
128
136
|
});
|
129
|
-
|
130
|
-
});
|
137
|
+
};
|
131
138
|
|
132
139
|
const template = `
|
140
|
+
import { getContext } from '@keystone-6/core/context';
|
133
141
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
134
142
|
import keystoneConfig from '../../../../../keystone';
|
135
|
-
import
|
136
|
-
import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
|
143
|
+
import * as PrismaModule from '.prisma/client';
|
137
144
|
|
138
|
-
const keystoneQueryAPI = global.keystoneQueryAPI ||
|
145
|
+
const keystoneQueryAPI = global.keystoneQueryAPI || getContext(keystoneConfig, PrismaModule).sudo().query;
|
139
146
|
|
140
147
|
if (process.env.NODE_ENV !== 'production') globalThis.keystoneQueryAPI = keystoneQueryAPI
|
141
148
|
|
@@ -151,13 +158,14 @@ export default getNextAuthPage({
|
|
151
158
|
sessionSecret: '<%= sessionSecret %>',
|
152
159
|
});
|
153
160
|
`;
|
154
|
-
const authTemplate =
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
+
const authTemplate = _ref => {
|
162
|
+
let {
|
163
|
+
autoCreate,
|
164
|
+
identityField,
|
165
|
+
listKey,
|
166
|
+
sessionData,
|
167
|
+
sessionSecret
|
168
|
+
} = _ref;
|
161
169
|
const authOut = ejs.render(template, {
|
162
170
|
identityField,
|
163
171
|
sessionData,
|
@@ -175,18 +183,19 @@ const _excluded = ["get", "end"];
|
|
175
183
|
* Generates config for Keystone to implement standard auth features.
|
176
184
|
*/
|
177
185
|
|
178
|
-
function createAuth({
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
186
|
+
function createAuth(_ref) {
|
187
|
+
let {
|
188
|
+
autoCreate,
|
189
|
+
cookies,
|
190
|
+
identityField,
|
191
|
+
listKey,
|
192
|
+
keystonePath,
|
193
|
+
pages,
|
194
|
+
resolver,
|
195
|
+
providers,
|
196
|
+
sessionData,
|
197
|
+
sessionSecret
|
198
|
+
} = _ref;
|
190
199
|
// The protectIdentities flag is currently under review to see whether it should be
|
191
200
|
// part of the createAuth API (in which case its use cases need to be documented and tested)
|
192
201
|
// or whether always being true is what we want, in which case we can refactor our code
|
@@ -203,10 +212,11 @@ function createAuth({
|
|
203
212
|
* - to the signin page when no valid session is present
|
204
213
|
*/
|
205
214
|
|
206
|
-
const pageMiddleware = async
|
207
|
-
|
208
|
-
|
209
|
-
|
215
|
+
const pageMiddleware = async _ref2 => {
|
216
|
+
let {
|
217
|
+
context,
|
218
|
+
isValidSession
|
219
|
+
} = _ref2;
|
210
220
|
const {
|
211
221
|
req,
|
212
222
|
session
|
@@ -347,12 +357,13 @@ function createAuth({
|
|
347
357
|
sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
|
348
358
|
|
349
359
|
return _objectSpread(_objectSpread({}, sessionStrategy), {}, {
|
350
|
-
get: async
|
351
|
-
req,
|
352
|
-
createContext
|
353
|
-
}) => {
|
360
|
+
get: async _ref3 => {
|
354
361
|
var _req$headers, _req$headers$authoriz;
|
355
362
|
|
363
|
+
let {
|
364
|
+
req,
|
365
|
+
createContext
|
366
|
+
} = _ref3;
|
356
367
|
const pathname = url.parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
357
368
|
let nextSession;
|
358
369
|
|
@@ -395,11 +406,12 @@ function createAuth({
|
|
395
406
|
itemId: nextSession.itemId
|
396
407
|
});
|
397
408
|
},
|
398
|
-
end: async
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
409
|
+
end: async _ref4 => {
|
410
|
+
let {
|
411
|
+
res,
|
412
|
+
req,
|
413
|
+
createContext
|
414
|
+
} = _ref4;
|
403
415
|
await end({
|
404
416
|
res,
|
405
417
|
req,
|
@@ -448,7 +460,6 @@ function createAuth({
|
|
448
460
|
|
449
461
|
return (await pageMiddleware(args)) ?? (keystoneConfig === null || keystoneConfig === void 0 ? void 0 : (_keystoneConfig$ui2 = keystoneConfig.ui) === null || _keystoneConfig$ui2 === void 0 ? void 0 : (_keystoneConfig$ui2$p = _keystoneConfig$ui2.pageMiddleware) === null || _keystoneConfig$ui2$p === void 0 ? void 0 : _keystoneConfig$ui2$p.call(_keystoneConfig$ui2, args));
|
450
462
|
},
|
451
|
-
enableSessionItem: true,
|
452
463
|
isAccessAllowed: async context => {
|
453
464
|
var _context$req, _keystoneConfig$ui3;
|
454
465
|
|
@@ -482,9 +493,6 @@ function createAuth({
|
|
482
493
|
resolver,
|
483
494
|
session,
|
484
495
|
lists: _objectSpread({}, keystoneConfig.lists),
|
485
|
-
experimental: _objectSpread(_objectSpread({}, keystoneConfig.experimental), {}, {
|
486
|
-
generateNodeAPI: true
|
487
|
-
}),
|
488
496
|
extendGraphqlSchema: existingExtendGraphQLSchema ? schema => existingExtendGraphQLSchema(extendGraphqlSchema(schema)) : extendGraphqlSchema
|
489
497
|
});
|
490
498
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@opensaas/keystone-nextjs-auth",
|
3
|
-
"version": "
|
3
|
+
"version": "25.0.0-rc-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",
|
@@ -13,18 +13,15 @@
|
|
13
13
|
"cross-fetch": "^3.1.5",
|
14
14
|
"ejs": "^3.1.8",
|
15
15
|
"fast-deep-equal": "^3.1.3",
|
16
|
-
"next-auth": "^4.10.
|
16
|
+
"next-auth": "^4.10.3"
|
17
17
|
},
|
18
18
|
"devDependencies": {
|
19
|
-
"@keystone-6/core": "
|
20
|
-
"react": "^18.
|
19
|
+
"@keystone-6/core": "0.0.0-rc-20221013033655",
|
20
|
+
"react": "^18.2.0"
|
21
21
|
},
|
22
22
|
"peerDependencies": {
|
23
|
-
"@keystone-6/core": "
|
24
|
-
"react": "^18.
|
25
|
-
},
|
26
|
-
"engines": {
|
27
|
-
"node": "^14.13 || >= 16.13"
|
23
|
+
"@keystone-6/core": "0.0.0-rc-20221013033655",
|
24
|
+
"react": "^18.2.0"
|
28
25
|
},
|
29
26
|
"publishConfig": {
|
30
27
|
"access": "public"
|
@@ -90,11 +90,12 @@ function NextAuthPage(props) {
|
|
90
90
|
jwt: jwt || {},
|
91
91
|
secret: sessionSecret,
|
92
92
|
callbacks: {
|
93
|
-
async signIn({
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
93
|
+
async signIn(_ref) {
|
94
|
+
let {
|
95
|
+
user,
|
96
|
+
account,
|
97
|
+
profile
|
98
|
+
} = _ref;
|
98
99
|
let identity;
|
99
100
|
|
100
101
|
if (typeof user.id === 'string') {
|
@@ -152,16 +153,18 @@ function NextAuthPage(props) {
|
|
152
153
|
return updateUser.success;
|
153
154
|
},
|
154
155
|
|
155
|
-
async redirect({
|
156
|
-
|
157
|
-
|
156
|
+
async redirect(_ref2) {
|
157
|
+
let {
|
158
|
+
url
|
159
|
+
} = _ref2;
|
158
160
|
return url;
|
159
161
|
},
|
160
162
|
|
161
|
-
async session({
|
162
|
-
|
163
|
-
|
164
|
-
|
163
|
+
async session(_ref3) {
|
164
|
+
let {
|
165
|
+
session,
|
166
|
+
token
|
167
|
+
} = _ref3;
|
165
168
|
let returnSession = session;
|
166
169
|
|
167
170
|
if (!token.itemId) {
|
@@ -180,9 +183,10 @@ function NextAuthPage(props) {
|
|
180
183
|
return returnSession;
|
181
184
|
},
|
182
185
|
|
183
|
-
async jwt({
|
184
|
-
|
185
|
-
|
186
|
+
async jwt(_ref4) {
|
187
|
+
let {
|
188
|
+
token
|
189
|
+
} = _ref4;
|
186
190
|
const identity = token.sub;
|
187
191
|
const result = await validateNextAuth(identityField, identity, protectIdentities, list);
|
188
192
|
|
package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.prod.js
CHANGED
@@ -90,11 +90,12 @@ function NextAuthPage(props) {
|
|
90
90
|
jwt: jwt || {},
|
91
91
|
secret: sessionSecret,
|
92
92
|
callbacks: {
|
93
|
-
async signIn({
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
93
|
+
async signIn(_ref) {
|
94
|
+
let {
|
95
|
+
user,
|
96
|
+
account,
|
97
|
+
profile
|
98
|
+
} = _ref;
|
98
99
|
let identity;
|
99
100
|
|
100
101
|
if (typeof user.id === 'string') {
|
@@ -152,16 +153,18 @@ function NextAuthPage(props) {
|
|
152
153
|
return updateUser.success;
|
153
154
|
},
|
154
155
|
|
155
|
-
async redirect({
|
156
|
-
|
157
|
-
|
156
|
+
async redirect(_ref2) {
|
157
|
+
let {
|
158
|
+
url
|
159
|
+
} = _ref2;
|
158
160
|
return url;
|
159
161
|
},
|
160
162
|
|
161
|
-
async session({
|
162
|
-
|
163
|
-
|
164
|
-
|
163
|
+
async session(_ref3) {
|
164
|
+
let {
|
165
|
+
session,
|
166
|
+
token
|
167
|
+
} = _ref3;
|
165
168
|
let returnSession = session;
|
166
169
|
|
167
170
|
if (!token.itemId) {
|
@@ -180,9 +183,10 @@ function NextAuthPage(props) {
|
|
180
183
|
return returnSession;
|
181
184
|
},
|
182
185
|
|
183
|
-
async jwt({
|
184
|
-
|
185
|
-
|
186
|
+
async jwt(_ref4) {
|
187
|
+
let {
|
188
|
+
token
|
189
|
+
} = _ref4;
|
186
190
|
const identity = token.sub;
|
187
191
|
const result = await validateNextAuth(identityField, identity, protectIdentities, list);
|
188
192
|
|
@@ -82,11 +82,12 @@ function NextAuthPage(props) {
|
|
82
82
|
jwt: jwt || {},
|
83
83
|
secret: sessionSecret,
|
84
84
|
callbacks: {
|
85
|
-
async signIn({
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
async signIn(_ref) {
|
86
|
+
let {
|
87
|
+
user,
|
88
|
+
account,
|
89
|
+
profile
|
90
|
+
} = _ref;
|
90
91
|
let identity;
|
91
92
|
|
92
93
|
if (typeof user.id === 'string') {
|
@@ -144,16 +145,18 @@ function NextAuthPage(props) {
|
|
144
145
|
return updateUser.success;
|
145
146
|
},
|
146
147
|
|
147
|
-
async redirect({
|
148
|
-
|
149
|
-
|
148
|
+
async redirect(_ref2) {
|
149
|
+
let {
|
150
|
+
url
|
151
|
+
} = _ref2;
|
150
152
|
return url;
|
151
153
|
},
|
152
154
|
|
153
|
-
async session({
|
154
|
-
|
155
|
-
|
156
|
-
|
155
|
+
async session(_ref3) {
|
156
|
+
let {
|
157
|
+
session,
|
158
|
+
token
|
159
|
+
} = _ref3;
|
157
160
|
let returnSession = session;
|
158
161
|
|
159
162
|
if (!token.itemId) {
|
@@ -172,9 +175,10 @@ function NextAuthPage(props) {
|
|
172
175
|
return returnSession;
|
173
176
|
},
|
174
177
|
|
175
|
-
async jwt({
|
176
|
-
|
177
|
-
|
178
|
+
async jwt(_ref4) {
|
179
|
+
let {
|
180
|
+
token
|
181
|
+
} = _ref4;
|
178
182
|
const identity = token.sub;
|
179
183
|
const result = await validateNextAuth(identityField, identity, protectIdentities, list);
|
180
184
|
|
package/src/index.ts
CHANGED
@@ -284,7 +284,6 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
|
|
284
284
|
getAdditionalFiles: [...(keystoneConfig.ui?.getAdditionalFiles || []), getAdditionalFiles],
|
285
285
|
pageMiddleware: async args =>
|
286
286
|
(await pageMiddleware(args)) ?? keystoneConfig?.ui?.pageMiddleware?.(args),
|
287
|
-
enableSessionItem: true,
|
288
287
|
isAccessAllowed: async (context: KeystoneContext) => {
|
289
288
|
const { req } = context;
|
290
289
|
const pathname = url.parse(req?.url!).pathname!;
|
@@ -326,10 +325,6 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
|
|
326
325
|
lists: {
|
327
326
|
...keystoneConfig.lists,
|
328
327
|
},
|
329
|
-
experimental: {
|
330
|
-
...keystoneConfig.experimental,
|
331
|
-
generateNodeAPI: true,
|
332
|
-
},
|
333
328
|
extendGraphqlSchema: existingExtendGraphQLSchema
|
334
329
|
? schema => existingExtendGraphQLSchema(extendGraphqlSchema(schema))
|
335
330
|
: extendGraphqlSchema,
|
package/src/templates/auth.ejs
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
-
import
|
2
|
-
import
|
1
|
+
import { getContext } from '@keystone-6/core/context';
|
2
|
+
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
3
|
+
import keystoneConfig from '../../../../../keystone';
|
4
|
+
import * as PrismaModule from '.prisma/client';
|
5
|
+
|
6
|
+
const keystoneQueryAPI = global.keystoneQueryAPI || getContext(keystoneConfig, PrismaModule).sudo().query;
|
7
|
+
|
8
|
+
if (process.env.NODE_ENV !== 'production') globalThis.keystoneQueryAPI = keystoneQueryAPI
|
3
9
|
|
4
10
|
export default getNextAuthPage({
|
11
|
+
autoCreate: <%= autoCreate %>,
|
5
12
|
identityField: '<%= identityField %>',
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}),
|
14
|
-
<% }) %>
|
15
|
-
],
|
13
|
+
listKey: '<%= listKey %>',
|
14
|
+
pages: keystoneConfig.pages,
|
15
|
+
providers: keystoneConfig.providers,
|
16
|
+
query: keystoneQueryAPI,
|
17
|
+
resolver: keystoneConfig.resolver,
|
18
|
+
sessionData: '<%= sessionData %>',
|
19
|
+
sessionSecret: '<%= sessionSecret %>',
|
16
20
|
});
|
package/src/templates/auth.ts
CHANGED
@@ -2,12 +2,12 @@ import ejs from 'ejs';
|
|
2
2
|
import { NextAuthTemplateProps } from '../pages/NextAuthPage';
|
3
3
|
|
4
4
|
const template = `
|
5
|
+
import { getContext } from '@keystone-6/core/context';
|
5
6
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
6
7
|
import keystoneConfig from '../../../../../keystone';
|
7
|
-
import
|
8
|
-
import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
|
8
|
+
import * as PrismaModule from '.prisma/client';
|
9
9
|
|
10
|
-
const keystoneQueryAPI = global.keystoneQueryAPI ||
|
10
|
+
const keystoneQueryAPI = global.keystoneQueryAPI || getContext(keystoneConfig, PrismaModule).sudo().query;
|
11
11
|
|
12
12
|
if (process.env.NODE_ENV !== 'production') globalThis.keystoneQueryAPI = keystoneQueryAPI
|
13
13
|
|