@opensaas/keystone-nextjs-auth 20.4.0 → 21.1.0
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 +4 -4
- 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 +66 -75
- package/dist/opensaas-keystone-nextjs-auth.cjs.prod.js +64 -75
- package/dist/opensaas-keystone-nextjs-auth.esm.js +64 -75
- package/package.json +10 -9
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.dev.js +36 -29
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.cjs.prod.js +36 -29
- package/pages/NextAuthPage/dist/opensaas-keystone-nextjs-auth-pages-NextAuthPage.esm.js +36 -29
- package/src/gql/getBaseAuthSchema.ts +0 -4
- package/src/index.ts +61 -64
- package/src/pages/NextAuthPage.tsx +58 -37
- 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
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# @opensaas-keystone/nextjs-auth
|
2
2
|
|
3
|
+
## 21.1.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- 9d35d01: Patch dependancies
|
8
|
+
- 4a593d7: dependancy updates
|
9
|
+
|
10
|
+
## 21.0.0
|
11
|
+
|
12
|
+
### Major Changes
|
13
|
+
|
14
|
+
- 4119c1c: Add ability to configure custom pages use `pages` configuration
|
15
|
+
- 4119c1c: Move `userMap` `accountMap` and `userMap` into a resolver function - `resolver` function takes in `{user,account,profile}` and returns a object that is passed in to create the identity
|
16
|
+
|
17
|
+
## 20.5.0
|
18
|
+
|
19
|
+
### Minor Changes
|
20
|
+
|
21
|
+
- e2e7122: upgrade keystone to `1.1.0`
|
22
|
+
|
3
23
|
## 20.4.0
|
4
24
|
|
5
25
|
### Minor Changes
|
package/README.md
CHANGED
@@ -44,9 +44,11 @@ const auth = createAuth({
|
|
44
44
|
identityField: 'subjectId',
|
45
45
|
sessionData: `id name email`,
|
46
46
|
autoCreate: true,
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
resolver: async ({user, profile, account}) => {
|
48
|
+
const username = user.name as string;
|
49
|
+
const email = user.email as string;
|
50
|
+
return { email, username };
|
51
|
+
},
|
50
52
|
keystonePath: '/admin',
|
51
53
|
sessionSecret,
|
52
54
|
providers: [
|
@@ -1,9 +1,7 @@
|
|
1
1
|
import type { BaseItem } from '@keystone-6/core/types';
|
2
2
|
import { graphql } from '@keystone-6/core';
|
3
|
-
|
4
|
-
export declare function getBaseAuthSchema({ listKey, gqlNames, base, }: {
|
3
|
+
export declare function getBaseAuthSchema({ listKey, base, }: {
|
5
4
|
listKey: string;
|
6
|
-
gqlNames: AuthGqlNames;
|
7
5
|
base: graphql.BaseSchemaMeta;
|
8
6
|
}): {
|
9
7
|
extension: {
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { BaseListTypeInfo, KeystoneConfig } from '@keystone-6/core/types';
|
2
|
-
import { AuthConfig,
|
2
|
+
import { AuthConfig, KeystoneOAuthConfig } from './types';
|
3
3
|
/**
|
4
4
|
* createAuth function
|
5
5
|
*
|
6
6
|
* Generates config for Keystone to implement standard auth features.
|
7
7
|
*/
|
8
|
-
export type { NextAuthProviders,
|
9
|
-
export declare function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
|
10
|
-
withAuth: (keystoneConfig: KeystoneConfig) =>
|
8
|
+
export type { NextAuthProviders, KeystoneOAuthConfig } from './types';
|
9
|
+
export declare function createAuth<GeneratedListTypes extends BaseListTypeInfo>({ autoCreate, cookies, identityField, listKey, keystonePath, pages, resolver, providers, sessionData, sessionSecret, }: AuthConfig<GeneratedListTypes>): {
|
10
|
+
withAuth: (keystoneConfig: KeystoneConfig) => KeystoneOAuthConfig;
|
11
11
|
};
|
@@ -1,18 +1,25 @@
|
|
1
|
+
import { CookiesOptions, EventCallbacks, PagesOptions } from 'next-auth';
|
1
2
|
import type { KeystoneListsAPI } from '@keystone-6/core/types';
|
2
3
|
import { Provider } from 'next-auth/providers';
|
3
|
-
|
4
|
+
import { JWTOptions } from 'next-auth/jwt';
|
5
|
+
declare type CoreNextAuthPageProps = {
|
6
|
+
autoCreate: boolean;
|
7
|
+
cookies?: Partial<CookiesOptions>;
|
8
|
+
events?: Partial<EventCallbacks>;
|
4
9
|
identityField: string;
|
5
|
-
|
6
|
-
providers: Provider[];
|
7
|
-
query: KeystoneListsAPI<any>;
|
8
|
-
sessionData: string;
|
10
|
+
jwt?: Partial<JWTOptions>;
|
9
11
|
listKey: string;
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
pages?: Partial<PagesOptions>;
|
13
|
+
providers?: Provider[];
|
14
|
+
resolver?: Function | undefined;
|
15
|
+
sessionData: string | undefined;
|
14
16
|
sessionSecret: string;
|
15
17
|
};
|
18
|
+
declare type NextAuthGglProps = {
|
19
|
+
mutationName?: string;
|
20
|
+
query?: KeystoneListsAPI<any>;
|
21
|
+
};
|
22
|
+
export declare type NextAuthPageProps = CoreNextAuthPageProps & NextAuthGglProps;
|
16
23
|
export default function NextAuthPage(props: NextAuthPageProps): any;
|
17
24
|
export declare const getNextAuthPage: (props: NextAuthPageProps) => () => any;
|
18
25
|
export {};
|
@@ -1,7 +1,5 @@
|
|
1
1
|
import { ExtendGraphqlSchema } from '@keystone-6/core/types';
|
2
|
-
|
3
|
-
export declare const getSchemaExtension: ({ identityField, listKey, gqlNames, }: {
|
2
|
+
export declare const getSchemaExtension: ({ listKey, }: {
|
4
3
|
identityField: string;
|
5
4
|
listKey: string;
|
6
|
-
gqlNames: AuthGqlNames;
|
7
5
|
}) => ExtendGraphqlSchema;
|
@@ -1,12 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
sessionData: any;
|
6
|
-
listKey: string;
|
7
|
-
autoCreate: boolean;
|
8
|
-
userMap: any;
|
9
|
-
accountMap: any;
|
10
|
-
profileMap: any;
|
11
|
-
sessionSecret: string;
|
12
|
-
}) => string;
|
1
|
+
import { NextAuthPageProps } from '../pages/NextAuthPage';
|
2
|
+
declare type AuthTemplateOptions = NextAuthPageProps;
|
3
|
+
export declare const authTemplate: ({ autoCreate, identityField, listKey, sessionData, sessionSecret, }: AuthTemplateOptions) => string;
|
4
|
+
export {};
|
@@ -1,42 +1,39 @@
|
|
1
1
|
import { BaseListTypeInfo, KeystoneConfig } from '@keystone-6/core/types';
|
2
|
+
import { CookiesOptions, PagesOptions } from 'next-auth';
|
2
3
|
import { Provider } from 'next-auth/providers';
|
3
|
-
export declare type AuthGqlNames = {
|
4
|
-
CreateInitialInput: string;
|
5
|
-
createInitialItem: string;
|
6
|
-
authenticateItemWithPassword: string;
|
7
|
-
ItemAuthenticationWithPasswordResult: string;
|
8
|
-
ItemAuthenticationWithPasswordSuccess: string;
|
9
|
-
ItemAuthenticationWithPasswordFailure: string;
|
10
|
-
};
|
11
4
|
export declare type NextAuthSession = {
|
12
5
|
listKey: string;
|
13
6
|
itemId: string;
|
14
7
|
data: any;
|
15
8
|
};
|
16
9
|
export declare type NextAuthProviders = Provider[];
|
17
|
-
declare type
|
10
|
+
declare type KeytoneOAuthOptions = {
|
18
11
|
providers: NextAuthProviders;
|
12
|
+
pages?: Partial<PagesOptions>;
|
13
|
+
};
|
14
|
+
declare type NextAuthOptions = {
|
15
|
+
cookies?: Partial<CookiesOptions>;
|
16
|
+
resolver: any;
|
19
17
|
};
|
20
|
-
export declare type
|
18
|
+
export declare type KeystoneOAuthConfig = KeystoneConfig & KeytoneOAuthOptions & NextAuthOptions;
|
21
19
|
export declare type AuthConfig<GeneratedListTypes extends BaseListTypeInfo> = {
|
20
|
+
/** Auth Create users in Keystone DB from Auth Provider */
|
21
|
+
autoCreate: boolean;
|
22
|
+
/** Adds ability to customize cookie options, for example, to facilitate cross-subdomain functionality */
|
23
|
+
cookies?: Partial<CookiesOptions>;
|
22
24
|
/** The key of the list to authenticate users with */
|
23
25
|
listKey: GeneratedListTypes['key'];
|
24
26
|
/** The path of the field the identity is stored in; must be text-ish */
|
25
27
|
identityField: GeneratedListTypes['fields'];
|
26
|
-
/** Session data population */
|
27
|
-
sessionData?: string;
|
28
|
-
/** Auth Create users in Keystone DB from Auth Provider */
|
29
|
-
autoCreate: boolean;
|
30
|
-
/** Map User in next-auth to item */
|
31
|
-
userMap: any;
|
32
|
-
/** Map Account in next-auth to item */
|
33
|
-
accountMap: any;
|
34
|
-
/** Map Profile in next-auth to item */
|
35
|
-
profileMap: any;
|
36
28
|
/** Path for Keystone interface */
|
37
29
|
keystonePath?: string;
|
30
|
+
pages?: any;
|
38
31
|
/** Providers for Next Auth */
|
39
32
|
providers: NextAuthProviders;
|
33
|
+
/** Resolver for user to define their profile */
|
34
|
+
resolver?: Function | undefined;
|
35
|
+
/** Session data population */
|
36
|
+
sessionData?: string | undefined;
|
40
37
|
/** Next-Auth Session Secret */
|
41
38
|
sessionSecret: string;
|
42
39
|
};
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
6
6
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
7
7
|
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
8
|
+
var _indexOfInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/index-of');
|
9
|
+
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
8
10
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
9
11
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
10
12
|
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
@@ -14,7 +16,6 @@ var jwt = require('next-auth/jwt');
|
|
14
16
|
var cookie = require('cookie');
|
15
17
|
var ejs = require('ejs');
|
16
18
|
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
17
|
-
var graphql = require('graphql');
|
18
19
|
var core = require('@keystone-6/core');
|
19
20
|
|
20
21
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
@@ -38,6 +39,8 @@ function _interopNamespace(e) {
|
|
38
39
|
}
|
39
40
|
|
40
41
|
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
42
|
+
var _indexOfInstanceProperty__default = /*#__PURE__*/_interopDefault(_indexOfInstanceProperty);
|
43
|
+
var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
|
41
44
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
42
45
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
43
46
|
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
@@ -55,6 +58,9 @@ module.exports = withPreconstruct({
|
|
55
58
|
typescript: {
|
56
59
|
ignoreBuildErrors: true,
|
57
60
|
},
|
61
|
+
env: {
|
62
|
+
NEXTAUTH_URL: process.env.NEXTAUTH_URL || 'http://localhost:<%= process.env.PORT || 3000 %><%= keystonePath || '' %>/api/auth',
|
63
|
+
},
|
58
64
|
eslint: {
|
59
65
|
ignoreDuringBuilds: true,
|
60
66
|
},
|
@@ -110,7 +116,6 @@ const nextConfigTemplate = ({
|
|
110
116
|
|
111
117
|
function getBaseAuthSchema({
|
112
118
|
listKey,
|
113
|
-
gqlNames,
|
114
119
|
base
|
115
120
|
}) {
|
116
121
|
const extension = {
|
@@ -150,22 +155,12 @@ function getBaseAuthSchema({
|
|
150
155
|
}
|
151
156
|
|
152
157
|
const getSchemaExtension = ({
|
153
|
-
|
154
|
-
listKey,
|
155
|
-
gqlNames
|
158
|
+
listKey
|
156
159
|
}) => core.graphql.extend(base => {
|
157
160
|
var _context;
|
158
161
|
|
159
|
-
const uniqueWhereInputType = graphql.assertInputObjectType(base.schema.getType(`${listKey}WhereUniqueInput`));
|
160
|
-
const identityFieldOnUniqueWhere = uniqueWhereInputType.getFields()[identityField];
|
161
|
-
|
162
|
-
if ((identityFieldOnUniqueWhere === null || identityFieldOnUniqueWhere === void 0 ? void 0 : identityFieldOnUniqueWhere.type) !== graphql.GraphQLString && (identityFieldOnUniqueWhere === null || identityFieldOnUniqueWhere === void 0 ? void 0 : identityFieldOnUniqueWhere.type) !== graphql.GraphQLID) {
|
163
|
-
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}`);
|
164
|
-
}
|
165
|
-
|
166
162
|
const baseSchema = getBaseAuthSchema({
|
167
163
|
listKey,
|
168
|
-
gqlNames,
|
169
164
|
base
|
170
165
|
});
|
171
166
|
return _filterInstanceProperty__default["default"](_context = [baseSchema.extension]).call(_context, x => x !== undefined);
|
@@ -177,38 +172,29 @@ import { query } from '.keystone/api';
|
|
177
172
|
import keystoneConfig from '../../../../../keystone';
|
178
173
|
|
179
174
|
export default getNextAuthPage({
|
175
|
+
autoCreate: <%= autoCreate %>,
|
180
176
|
identityField: '<%= identityField %>',
|
181
|
-
sessionData: '<%= sessionData %>',
|
182
177
|
listKey: '<%= listKey %>',
|
183
|
-
|
184
|
-
accountMap: <%- JSON.stringify(accountMap) %>,
|
185
|
-
profileMap: <%- JSON.stringify(profileMap) %>,
|
186
|
-
autoCreate: <%= autoCreate %>,
|
187
|
-
sessionSecret: '<%= sessionSecret %>',
|
178
|
+
pages: keystoneConfig.pages,
|
188
179
|
providers: keystoneConfig.providers,
|
189
180
|
query,
|
181
|
+
resolver: keystoneConfig.resolver,
|
182
|
+
sessionData: '<%= sessionData %>',
|
183
|
+
sessionSecret: '<%= sessionSecret %>',
|
190
184
|
});
|
191
185
|
`;
|
192
186
|
const authTemplate = ({
|
193
|
-
|
187
|
+
autoCreate,
|
194
188
|
identityField,
|
195
|
-
sessionData,
|
196
189
|
listKey,
|
197
|
-
|
198
|
-
userMap,
|
199
|
-
accountMap,
|
200
|
-
profileMap,
|
190
|
+
sessionData,
|
201
191
|
sessionSecret
|
202
192
|
}) => {
|
203
193
|
const authOut = ejs__default["default"].render(template, {
|
204
|
-
gqlNames,
|
205
194
|
identityField,
|
206
195
|
sessionData,
|
207
196
|
listKey,
|
208
197
|
autoCreate,
|
209
|
-
userMap,
|
210
|
-
accountMap,
|
211
|
-
profileMap,
|
212
198
|
sessionSecret
|
213
199
|
});
|
214
200
|
return authOut;
|
@@ -222,31 +208,21 @@ const _excluded = ["get", "start"];
|
|
222
208
|
*/
|
223
209
|
|
224
210
|
function createAuth({
|
225
|
-
listKey,
|
226
|
-
identityField,
|
227
|
-
sessionData,
|
228
211
|
autoCreate,
|
229
|
-
|
230
|
-
|
231
|
-
|
212
|
+
cookies,
|
213
|
+
identityField,
|
214
|
+
listKey,
|
232
215
|
keystonePath,
|
216
|
+
pages,
|
217
|
+
resolver,
|
233
218
|
providers,
|
219
|
+
sessionData,
|
234
220
|
sessionSecret
|
235
221
|
}) {
|
236
222
|
// The protectIdentities flag is currently under review to see whether it should be
|
237
223
|
// part of the createAuth API (in which case its use cases need to be documented and tested)
|
238
224
|
// or whether always being true is what we want, in which case we can refactor our code
|
239
225
|
// to match this. -TL
|
240
|
-
const gqlNames = {
|
241
|
-
// Core
|
242
|
-
authenticateItemWithPassword: `authenticate${listKey}WithPassword`,
|
243
|
-
ItemAuthenticationWithPasswordResult: `${listKey}AuthenticationWithPasswordResult`,
|
244
|
-
ItemAuthenticationWithPasswordSuccess: `${listKey}AuthenticationWithPasswordSuccess`,
|
245
|
-
ItemAuthenticationWithPasswordFailure: `${listKey}AuthenticationWithPasswordFailure`,
|
246
|
-
// Initial data
|
247
|
-
CreateInitialInput: `CreateInitial${listKey}Input`,
|
248
|
-
createInitialItem: `createInitial${listKey}`
|
249
|
-
};
|
250
226
|
const customPath = !keystonePath || keystonePath === '/' ? '' : keystonePath;
|
251
227
|
/**
|
252
228
|
* pageMiddleware
|
@@ -263,16 +239,14 @@ function createAuth({
|
|
263
239
|
context,
|
264
240
|
isValidSession
|
265
241
|
}) => {
|
242
|
+
var _context;
|
243
|
+
|
266
244
|
const {
|
267
245
|
req,
|
268
246
|
session
|
269
247
|
} = context;
|
270
248
|
const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname;
|
271
249
|
|
272
|
-
if (pathname === `${customPath}/api/__keystone_api_build`) {
|
273
|
-
return;
|
274
|
-
}
|
275
|
-
|
276
250
|
if (isValidSession) {
|
277
251
|
if (pathname === `${customPath}/api/auth/signin`) {
|
278
252
|
return {
|
@@ -291,7 +265,11 @@ function createAuth({
|
|
291
265
|
return;
|
292
266
|
}
|
293
267
|
|
294
|
-
if (
|
268
|
+
if (_includesInstanceProperty__default["default"](pathname).call(pathname, '/_next/') || _includesInstanceProperty__default["default"](pathname).call(pathname, '/api/auth/')) {
|
269
|
+
return;
|
270
|
+
}
|
271
|
+
|
272
|
+
if (!session && !_includesInstanceProperty__default["default"](pathname).call(pathname, `${customPath}/api/auth/`) && !(_indexOfInstanceProperty__default["default"](_context = _Object$values__default["default"](pages)).call(_context, pathname) > -1)) {
|
295
273
|
return {
|
296
274
|
kind: 'redirect',
|
297
275
|
to: `${customPath}/api/auth/signin`
|
@@ -313,14 +291,10 @@ function createAuth({
|
|
313
291
|
mode: 'write',
|
314
292
|
outputPath: 'pages/api/auth/[...nextauth].js',
|
315
293
|
src: authTemplate({
|
316
|
-
|
294
|
+
autoCreate,
|
317
295
|
identityField,
|
318
|
-
sessionData,
|
319
296
|
listKey,
|
320
|
-
|
321
|
-
userMap,
|
322
|
-
accountMap,
|
323
|
-
profileMap,
|
297
|
+
sessionData,
|
324
298
|
sessionSecret
|
325
299
|
})
|
326
300
|
}, {
|
@@ -339,7 +313,8 @@ function createAuth({
|
|
339
313
|
*/
|
340
314
|
|
341
315
|
|
342
|
-
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`];
|
316
|
+
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
|
317
|
+
// @ts-ignore
|
343
318
|
|
344
319
|
function addPages(provider) {
|
345
320
|
const name = provider.id;
|
@@ -357,8 +332,7 @@ function createAuth({
|
|
357
332
|
|
358
333
|
const extendGraphqlSchema = getSchemaExtension({
|
359
334
|
identityField,
|
360
|
-
listKey
|
361
|
-
gqlNames
|
335
|
+
listKey
|
362
336
|
});
|
363
337
|
/**
|
364
338
|
* validateConfig
|
@@ -372,7 +346,9 @@ function createAuth({
|
|
372
346
|
if (listConfig === undefined) {
|
373
347
|
const msg = `A createAuth() invocation specifies the list "${listKey}" but no list with that key has been defined.`;
|
374
348
|
throw new Error(msg);
|
375
|
-
} // TODO: Check
|
349
|
+
} // TODO: Check if providers
|
350
|
+
// TODO: Check other required commands/data
|
351
|
+
// TODO: Check for String-like typing for identityField? How?
|
376
352
|
// TODO: Validate that the identifyField is unique.
|
377
353
|
// TODO: If this field isn't required, what happens if I try to log in as `null`?
|
378
354
|
|
@@ -380,9 +356,9 @@ function createAuth({
|
|
380
356
|
const identityFieldConfig = listConfig.fields[identityField];
|
381
357
|
|
382
358
|
if (identityFieldConfig === undefined) {
|
383
|
-
const
|
359
|
+
const identityFieldName = _JSON$stringify__default["default"](identityField);
|
384
360
|
|
385
|
-
const msg = `A createAuth() invocation for the "${listKey}" list specifies ${
|
361
|
+
const msg = `A createAuth() invocation for the "${listKey}" list specifies ${identityFieldName} as its identityField but no field with that key exists on the list.`;
|
386
362
|
throw new Error(msg);
|
387
363
|
}
|
388
364
|
};
|
@@ -405,7 +381,15 @@ function createAuth({
|
|
405
381
|
sessionStrategy = _objectWithoutProperties(_sessionStrategy, _excluded);
|
406
382
|
|
407
383
|
return _objectSpread(_objectSpread({}, sessionStrategy), {}, {
|
408
|
-
start
|
384
|
+
start: async ({
|
385
|
+
res
|
386
|
+
}) => {
|
387
|
+
console.log('start');
|
388
|
+
const session = await start({
|
389
|
+
res
|
390
|
+
});
|
391
|
+
return session;
|
392
|
+
},
|
409
393
|
get: async ({
|
410
394
|
req
|
411
395
|
}) => {
|
@@ -420,9 +404,8 @@ function createAuth({
|
|
420
404
|
if (((_req$headers$authoriz = req.headers.authorization) === null || _req$headers$authoriz === void 0 ? void 0 : _req$headers$authoriz.split(' ')[0]) === 'Bearer') {
|
421
405
|
var _token$data;
|
422
406
|
|
423
|
-
const request = req;
|
424
407
|
const token = await jwt.getToken({
|
425
|
-
req
|
408
|
+
req,
|
426
409
|
secret: sessionSecret
|
427
410
|
});
|
428
411
|
|
@@ -451,6 +434,7 @@ function createAuth({
|
|
451
434
|
secure: process.env.NODE_ENV === 'production',
|
452
435
|
path: '/',
|
453
436
|
sameSite: 'lax',
|
437
|
+
// TODO: Update parse to URL
|
454
438
|
domain: url__default["default"].parse(req.url).hostname
|
455
439
|
}));
|
456
440
|
}
|
@@ -487,19 +471,23 @@ function createAuth({
|
|
487
471
|
},
|
488
472
|
enableSessionItem: true,
|
489
473
|
isAccessAllowed: async context => {
|
490
|
-
var _context$req,
|
474
|
+
var _context$req, _keystoneConfig$ui3;
|
491
475
|
|
492
|
-
|
476
|
+
const {
|
477
|
+
req
|
478
|
+
} = context;
|
479
|
+
const pathname = url__default["default"].parse(req === null || req === void 0 ? void 0 : req.url).pathname; // Allow nextjs scripts and static files to be accessed without auth
|
480
|
+
|
481
|
+
if (_includesInstanceProperty__default["default"](pathname).call(pathname, '/_next/')) {
|
493
482
|
return true;
|
494
|
-
} // Allow
|
495
|
-
// even if the user isn't logged in (which should always be the case if they're seeing /init)
|
483
|
+
} // Allow keystone to access /api/__keystone_api_build for hot reloading
|
496
484
|
|
497
485
|
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
return
|
486
|
+
if (process.env.NODE_ENV !== 'production' && ((_context$req = context.req) === null || _context$req === void 0 ? void 0 : _context$req.url) !== undefined && new _URL__default["default"](context.req.url, 'http://example.com').pathname === `${customPath}/api/__keystone_api_build`) {
|
487
|
+
return true;
|
488
|
+
}
|
489
|
+
|
490
|
+
return (_keystoneConfig$ui3 = keystoneConfig.ui) !== null && _keystoneConfig$ui3 !== void 0 && _keystoneConfig$ui3.isAccessAllowed ? keystoneConfig.ui.isAccessAllowed(context) : context.session !== undefined;
|
503
491
|
}
|
504
492
|
});
|
505
493
|
}
|
@@ -509,8 +497,11 @@ function createAuth({
|
|
509
497
|
const existingExtendGraphQLSchema = keystoneConfig.extendGraphqlSchema;
|
510
498
|
return _objectSpread(_objectSpread({}, keystoneConfig), {}, {
|
511
499
|
ui,
|
512
|
-
|
500
|
+
cookies,
|
513
501
|
providers,
|
502
|
+
pages,
|
503
|
+
resolver,
|
504
|
+
session,
|
514
505
|
lists: _objectSpread({}, keystoneConfig.lists),
|
515
506
|
experimental: _objectSpread(_objectSpread({}, keystoneConfig.experimental), {}, {
|
516
507
|
generateNodeAPI: true
|