@opensaas/keystone-nextjs-auth 24.1.0 → 25.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 +10 -0
- package/dist/declarations/src/gql/getBaseAuthSchema.d.ts +1 -1
- package/dist/opensaas-keystone-nextjs-auth.cjs.dev.js +3 -16
- package/dist/opensaas-keystone-nextjs-auth.cjs.prod.js +3 -16
- package/dist/opensaas-keystone-nextjs-auth.esm.js +3 -16
- package/package.json +4 -7
- package/src/index.ts +4 -9
- package/src/templates/auth.ejs +16 -12
- package/src/templates/auth.ts +3 -12
package/CHANGELOG.md
CHANGED
@@ -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
|
};
|
@@ -170,21 +170,12 @@ const getSchemaExtension = _ref => {
|
|
170
170
|
};
|
171
171
|
|
172
172
|
const template = `
|
173
|
+
import { getContext } from '@keystone-6/core/context';
|
173
174
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
174
175
|
import keystoneConfig from '../../../../../keystone';
|
175
|
-
import
|
176
|
-
import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
|
177
|
-
|
178
|
-
const cleanConfig = (config) => {
|
179
|
-
const { db, ...rest } = config;
|
180
|
-
if (db) {
|
181
|
-
const { onConnect, ...restDB } = db;
|
182
|
-
return { ...rest, db: restDB };
|
183
|
-
}
|
184
|
-
return rest;
|
185
|
-
};
|
176
|
+
import * as PrismaModule from '.prisma/client';
|
186
177
|
|
187
|
-
const keystoneQueryAPI = global.keystoneQueryAPI ||
|
178
|
+
const keystoneQueryAPI = global.keystoneQueryAPI || getContext(keystoneConfig, PrismaModule).sudo().query;
|
188
179
|
|
189
180
|
if (process.env.NODE_ENV !== 'production') globalThis.keystoneQueryAPI = keystoneQueryAPI
|
190
181
|
|
@@ -502,7 +493,6 @@ function createAuth(_ref) {
|
|
502
493
|
|
503
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));
|
504
495
|
},
|
505
|
-
enableSessionItem: true,
|
506
496
|
isAccessAllowed: async context => {
|
507
497
|
var _context$req, _keystoneConfig$ui3;
|
508
498
|
|
@@ -536,9 +526,6 @@ function createAuth(_ref) {
|
|
536
526
|
resolver,
|
537
527
|
session,
|
538
528
|
lists: _objectSpread({}, keystoneConfig.lists),
|
539
|
-
experimental: _objectSpread(_objectSpread({}, keystoneConfig.experimental), {}, {
|
540
|
-
generateNodeAPI: true
|
541
|
-
}),
|
542
529
|
extendGraphqlSchema: existingExtendGraphQLSchema ? schema => existingExtendGraphQLSchema(extendGraphqlSchema(schema)) : extendGraphqlSchema
|
543
530
|
});
|
544
531
|
};
|
@@ -169,21 +169,12 @@ const getSchemaExtension = _ref => {
|
|
169
169
|
};
|
170
170
|
|
171
171
|
const template = `
|
172
|
+
import { getContext } from '@keystone-6/core/context';
|
172
173
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
173
174
|
import keystoneConfig from '../../../../../keystone';
|
174
|
-
import
|
175
|
-
import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
|
176
|
-
|
177
|
-
const cleanConfig = (config) => {
|
178
|
-
const { db, ...rest } = config;
|
179
|
-
if (db) {
|
180
|
-
const { onConnect, ...restDB } = db;
|
181
|
-
return { ...rest, db: restDB };
|
182
|
-
}
|
183
|
-
return rest;
|
184
|
-
};
|
175
|
+
import * as PrismaModule from '.prisma/client';
|
185
176
|
|
186
|
-
const keystoneQueryAPI = global.keystoneQueryAPI ||
|
177
|
+
const keystoneQueryAPI = global.keystoneQueryAPI || getContext(keystoneConfig, PrismaModule).sudo().query;
|
187
178
|
|
188
179
|
if (process.env.NODE_ENV !== 'production') globalThis.keystoneQueryAPI = keystoneQueryAPI
|
189
180
|
|
@@ -501,7 +492,6 @@ function createAuth(_ref) {
|
|
501
492
|
|
502
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));
|
503
494
|
},
|
504
|
-
enableSessionItem: true,
|
505
495
|
isAccessAllowed: async context => {
|
506
496
|
var _keystoneConfig$ui3;
|
507
497
|
|
@@ -530,9 +520,6 @@ function createAuth(_ref) {
|
|
530
520
|
resolver,
|
531
521
|
session,
|
532
522
|
lists: _objectSpread({}, keystoneConfig.lists),
|
533
|
-
experimental: _objectSpread(_objectSpread({}, keystoneConfig.experimental), {}, {
|
534
|
-
generateNodeAPI: true
|
535
|
-
}),
|
536
523
|
extendGraphqlSchema: existingExtendGraphQLSchema ? schema => existingExtendGraphQLSchema(extendGraphqlSchema(schema)) : extendGraphqlSchema
|
537
524
|
});
|
538
525
|
};
|
@@ -137,21 +137,12 @@ const getSchemaExtension = _ref => {
|
|
137
137
|
};
|
138
138
|
|
139
139
|
const template = `
|
140
|
+
import { getContext } from '@keystone-6/core/context';
|
140
141
|
import getNextAuthPage from '@opensaas/keystone-nextjs-auth/pages/NextAuthPage';
|
141
142
|
import keystoneConfig from '../../../../../keystone';
|
142
|
-
import
|
143
|
-
import { createQueryAPI } from '@keystone-6/core/___internal-do-not-use-will-break-in-patch/node-api';
|
144
|
-
|
145
|
-
const cleanConfig = (config) => {
|
146
|
-
const { db, ...rest } = config;
|
147
|
-
if (db) {
|
148
|
-
const { onConnect, ...restDB } = db;
|
149
|
-
return { ...rest, db: restDB };
|
150
|
-
}
|
151
|
-
return rest;
|
152
|
-
};
|
143
|
+
import * as PrismaModule from '.prisma/client';
|
153
144
|
|
154
|
-
const keystoneQueryAPI = global.keystoneQueryAPI ||
|
145
|
+
const keystoneQueryAPI = global.keystoneQueryAPI || getContext(keystoneConfig, PrismaModule).sudo().query;
|
155
146
|
|
156
147
|
if (process.env.NODE_ENV !== 'production') globalThis.keystoneQueryAPI = keystoneQueryAPI
|
157
148
|
|
@@ -469,7 +460,6 @@ function createAuth(_ref) {
|
|
469
460
|
|
470
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));
|
471
462
|
},
|
472
|
-
enableSessionItem: true,
|
473
463
|
isAccessAllowed: async context => {
|
474
464
|
var _context$req, _keystoneConfig$ui3;
|
475
465
|
|
@@ -503,9 +493,6 @@ function createAuth(_ref) {
|
|
503
493
|
resolver,
|
504
494
|
session,
|
505
495
|
lists: _objectSpread({}, keystoneConfig.lists),
|
506
|
-
experimental: _objectSpread(_objectSpread({}, keystoneConfig.experimental), {}, {
|
507
|
-
generateNodeAPI: true
|
508
|
-
}),
|
509
496
|
extendGraphqlSchema: existingExtendGraphQLSchema ? schema => existingExtendGraphQLSchema(extendGraphqlSchema(schema)) : extendGraphqlSchema
|
510
497
|
});
|
511
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",
|
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,19 +13,16 @@
|
|
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.
|
16
|
+
"next-auth": "^4.14.0"
|
17
17
|
},
|
18
18
|
"devDependencies": {
|
19
|
-
"@keystone-6/core": "
|
19
|
+
"@keystone-6/core": "3.0.0",
|
20
20
|
"react": "^18.2.0"
|
21
21
|
},
|
22
22
|
"peerDependencies": {
|
23
|
-
"@keystone-6/core": "
|
23
|
+
"@keystone-6/core": "3.0.0",
|
24
24
|
"react": "^18.2.0"
|
25
25
|
},
|
26
|
-
"engines": {
|
27
|
-
"node": "^14.13 || >= 16.13"
|
28
|
-
},
|
29
26
|
"publishConfig": {
|
30
27
|
"access": "public"
|
31
28
|
},
|
package/src/index.ts
CHANGED
@@ -14,7 +14,7 @@ import { Provider } from 'next-auth/providers';
|
|
14
14
|
|
15
15
|
import * as cookie from 'cookie';
|
16
16
|
|
17
|
-
import { Session } from 'next-auth';
|
17
|
+
import { JWT, Session } from 'next-auth';
|
18
18
|
import { nextConfigTemplate } from './templates/next-config';
|
19
19
|
// import * as Path from 'path';
|
20
20
|
|
@@ -199,17 +199,17 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
|
|
199
199
|
...sessionStrategy,
|
200
200
|
get: async ({ req, createContext }) => {
|
201
201
|
const pathname = url.parse(req?.url!).pathname!;
|
202
|
-
let nextSession: Session;
|
202
|
+
let nextSession: Session | JWT | null;
|
203
203
|
if (pathname.includes('/api/auth')) {
|
204
204
|
return;
|
205
205
|
}
|
206
206
|
const sudoContext = createContext({ sudo: true });
|
207
207
|
|
208
208
|
if (req.headers?.authorization?.split(' ')[0] === 'Bearer') {
|
209
|
-
nextSession =
|
209
|
+
nextSession = await getToken({
|
210
210
|
req,
|
211
211
|
secret: sessionSecret,
|
212
|
-
})
|
212
|
+
});
|
213
213
|
} else {
|
214
214
|
nextSession = (await getSession({ req })) as Session;
|
215
215
|
}
|
@@ -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,21 +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
|
11
|
-
const { db, ...rest } = config;
|
12
|
-
if (db) {
|
13
|
-
const { onConnect, ...restDB } = db;
|
14
|
-
return { ...rest, db: restDB };
|
15
|
-
}
|
16
|
-
return rest;
|
17
|
-
};
|
18
|
-
|
19
|
-
const keystoneQueryAPI = global.keystoneQueryAPI || createQueryAPI(cleanConfig(keystoneConfig), PrismaClient);
|
10
|
+
const keystoneQueryAPI = global.keystoneQueryAPI || getContext(keystoneConfig, PrismaModule).sudo().query;
|
20
11
|
|
21
12
|
if (process.env.NODE_ENV !== 'production') globalThis.keystoneQueryAPI = keystoneQueryAPI
|
22
13
|
|