@opensaas/keystone-nextjs-auth 20.0.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 CHANGED
@@ -1,5 +1,27 @@
1
1
  # @opensaas-keystone/nextjs-auth
2
2
 
3
+ ## 20.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 844f069: Generate NodeAPI by def, minor cleanups
8
+
9
+ ### Patch Changes
10
+
11
+ - 6d63b1f: Minor Patch upgrades
12
+
13
+ ## 20.1.1
14
+
15
+ ### Patch Changes
16
+
17
+ - 0b22f90: Fix Error where signin was returning deny on create user
18
+
19
+ ## 20.1.0
20
+
21
+ ### Minor Changes
22
+
23
+ - cd06bfa: upgrade to next-auth 4.1.0 and other minor upgrades
24
+
3
25
  ## 20.0.1
4
26
 
5
27
  ### Patch Changes
@@ -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(list: any, identityField: string, identity: string | number, protectIdentities: boolean, itemAPI: KeystoneListsAPI<any>[string]): Promise<{
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 = [Provider];
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,27 +1,27 @@
1
1
  {
2
2
  "name": "@opensaas/keystone-nextjs-auth",
3
- "version": "20.0.1",
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",
7
7
  "module": "dist/opensaas-keystone-nextjs-auth.esm.js",
8
8
  "dependencies": {
9
- "@babel/runtime": "^7.16.5",
10
- "@babel/runtime-corejs3": "^7.16.5",
9
+ "@babel/runtime": "^7.16.7",
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.4",
13
+ "cross-fetch": "^3.1.5",
14
14
  "ejs": "^3.1.6",
15
15
  "fast-deep-equal": "^3.1.3",
16
- "graphql": "^15.7.2",
17
- "next-auth": "^4.0.5"
16
+ "graphql": "^15.8.0",
17
+ "next-auth": "^4.1.2"
18
18
  },
19
19
  "devDependencies": {
20
- "@keystone-6/core": "^1.0.0",
20
+ "@keystone-6/core": "^1.0.1",
21
21
  "react": "^17.0.2"
22
22
  },
23
23
  "peerDependencies": {
24
- "@keystone-6/core": "^1.0.0",
24
+ "@keystone-6/core": "^1.0.1",
25
25
  "react": "^17.0.2"
26
26
  },
27
27
  "engines": {
@@ -3,10 +3,12 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
6
+ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
6
7
  var NextAuth = require('next-auth');
7
8
 
8
9
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
10
 
11
+ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
10
12
  var NextAuth__default = /*#__PURE__*/_interopDefault(NextAuth);
11
13
 
12
14
  async function findMatchingIdentity(identityField, identity, queryAPI) {
@@ -35,7 +37,7 @@ async function findMatchingIdentity(identityField, identity, queryAPI) {
35
37
  };
36
38
  }
37
39
 
38
- async function validateNextAuth(list, identityField, identity, protectIdentities, itemAPI) {
40
+ async function validateNextAuth(identityField, identity, protectIdentities, itemAPI) {
39
41
  const match = await findMatchingIdentity(identityField, identity, itemAPI);
40
42
  const {
41
43
  item
@@ -85,9 +87,11 @@ function NextAuthPage(props) {
85
87
  identity = user.id;
86
88
  } else if (typeof user.id === 'number') {
87
89
  identity = user.id;
90
+ } else {
91
+ identity = 0;
88
92
  }
89
93
 
90
- const result = await validateNextAuth(list, identityField, identity, protectIdentities, queryAPI);
94
+ const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
91
95
  const data = {}; // eslint-disable-next-line no-restricted-syntax
92
96
 
93
97
  for (const key in userMap) {
@@ -112,24 +116,26 @@ function NextAuthPage(props) {
112
116
 
113
117
  if (!result.success) {
114
118
  if (!autoCreate) {
115
- console.log('False');
119
+ console.log('`autoCreate` if set to `false`, skipping user auto-creation');
116
120
  return false;
117
121
  }
118
122
 
119
- console.log('Create User');
120
- await list.createOne({
123
+ console.log('`autoCreate` if set to `true`, auto-creating a new user');
124
+ const createUser = await list.createOne({
121
125
  data
122
126
  }).then(returned => {
123
- console.log(returned);
127
+ console.log('User Created', _JSON$stringify__default["default"](returned));
124
128
  return true;
125
129
  }).catch(error => {
126
130
  console.log(error);
127
131
  throw new Error(error);
128
132
  });
129
- } else {
130
- // await list.updateOne({where: {id: result.item.id}, data});
131
- return result.success;
132
- }
133
+ console.log('Created User', createUser);
134
+ return createUser;
135
+ } // await list.updateOne({where: {id: result.item.id}, data});
136
+
137
+
138
+ return result.success;
133
139
  },
134
140
 
135
141
  async redirect({
@@ -158,7 +164,7 @@ function NextAuthPage(props) {
158
164
  const identity = token.sub;
159
165
 
160
166
  if (!token.itemId) {
161
- const result = await validateNextAuth(list, identityField, identity, protectIdentities, queryAPI);
167
+ const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
162
168
 
163
169
  if (!result.success) {
164
170
  return;
@@ -3,10 +3,12 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
6
+ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
6
7
  var NextAuth = require('next-auth');
7
8
 
8
9
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
9
10
 
11
+ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
10
12
  var NextAuth__default = /*#__PURE__*/_interopDefault(NextAuth);
11
13
 
12
14
  async function findMatchingIdentity(identityField, identity, queryAPI) {
@@ -35,7 +37,7 @@ async function findMatchingIdentity(identityField, identity, queryAPI) {
35
37
  };
36
38
  }
37
39
 
38
- async function validateNextAuth(list, identityField, identity, protectIdentities, itemAPI) {
40
+ async function validateNextAuth(identityField, identity, protectIdentities, itemAPI) {
39
41
  const match = await findMatchingIdentity(identityField, identity, itemAPI);
40
42
  const {
41
43
  item
@@ -85,9 +87,11 @@ function NextAuthPage(props) {
85
87
  identity = user.id;
86
88
  } else if (typeof user.id === 'number') {
87
89
  identity = user.id;
90
+ } else {
91
+ identity = 0;
88
92
  }
89
93
 
90
- const result = await validateNextAuth(list, identityField, identity, protectIdentities, queryAPI);
94
+ const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
91
95
  const data = {}; // eslint-disable-next-line no-restricted-syntax
92
96
 
93
97
  for (const key in userMap) {
@@ -112,24 +116,26 @@ function NextAuthPage(props) {
112
116
 
113
117
  if (!result.success) {
114
118
  if (!autoCreate) {
115
- console.log('False');
119
+ console.log('`autoCreate` if set to `false`, skipping user auto-creation');
116
120
  return false;
117
121
  }
118
122
 
119
- console.log('Create User');
120
- await list.createOne({
123
+ console.log('`autoCreate` if set to `true`, auto-creating a new user');
124
+ const createUser = await list.createOne({
121
125
  data
122
126
  }).then(returned => {
123
- console.log(returned);
127
+ console.log('User Created', _JSON$stringify__default["default"](returned));
124
128
  return true;
125
129
  }).catch(error => {
126
130
  console.log(error);
127
131
  throw new Error(error);
128
132
  });
129
- } else {
130
- // await list.updateOne({where: {id: result.item.id}, data});
131
- return result.success;
132
- }
133
+ console.log('Created User', createUser);
134
+ return createUser;
135
+ } // await list.updateOne({where: {id: result.item.id}, data});
136
+
137
+
138
+ return result.success;
133
139
  },
134
140
 
135
141
  async redirect({
@@ -158,7 +164,7 @@ function NextAuthPage(props) {
158
164
  const identity = token.sub;
159
165
 
160
166
  if (!token.itemId) {
161
- const result = await validateNextAuth(list, identityField, identity, protectIdentities, queryAPI);
167
+ const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
162
168
 
163
169
  if (!result.success) {
164
170
  return;
@@ -1,4 +1,5 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
2
+ import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
2
3
  import NextAuth from 'next-auth';
3
4
 
4
5
  async function findMatchingIdentity(identityField, identity, queryAPI) {
@@ -27,7 +28,7 @@ async function findMatchingIdentity(identityField, identity, queryAPI) {
27
28
  };
28
29
  }
29
30
 
30
- async function validateNextAuth(list, identityField, identity, protectIdentities, itemAPI) {
31
+ async function validateNextAuth(identityField, identity, protectIdentities, itemAPI) {
31
32
  const match = await findMatchingIdentity(identityField, identity, itemAPI);
32
33
  const {
33
34
  item
@@ -77,9 +78,11 @@ function NextAuthPage(props) {
77
78
  identity = user.id;
78
79
  } else if (typeof user.id === 'number') {
79
80
  identity = user.id;
81
+ } else {
82
+ identity = 0;
80
83
  }
81
84
 
82
- const result = await validateNextAuth(list, identityField, identity, protectIdentities, queryAPI);
85
+ const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
83
86
  const data = {}; // eslint-disable-next-line no-restricted-syntax
84
87
 
85
88
  for (const key in userMap) {
@@ -104,24 +107,26 @@ function NextAuthPage(props) {
104
107
 
105
108
  if (!result.success) {
106
109
  if (!autoCreate) {
107
- console.log('False');
110
+ console.log('`autoCreate` if set to `false`, skipping user auto-creation');
108
111
  return false;
109
112
  }
110
113
 
111
- console.log('Create User');
112
- await list.createOne({
114
+ console.log('`autoCreate` if set to `true`, auto-creating a new user');
115
+ const createUser = await list.createOne({
113
116
  data
114
117
  }).then(returned => {
115
- console.log(returned);
118
+ console.log('User Created', _JSON$stringify(returned));
116
119
  return true;
117
120
  }).catch(error => {
118
121
  console.log(error);
119
122
  throw new Error(error);
120
123
  });
121
- } else {
122
- // await list.updateOne({where: {id: result.item.id}, data});
123
- return result.success;
124
- }
124
+ console.log('Created User', createUser);
125
+ return createUser;
126
+ } // await list.updateOne({where: {id: result.item.id}, data});
127
+
128
+
129
+ return result.success;
125
130
  },
126
131
 
127
132
  async redirect({
@@ -150,7 +155,7 @@ function NextAuthPage(props) {
150
155
  const identity = token.sub;
151
156
 
152
157
  if (!token.itemId) {
153
- const result = await validateNextAuth(list, identityField, identity, protectIdentities, queryAPI);
158
+ const result = await validateNextAuth(identityField, identity, protectIdentities, queryAPI);
154
159
 
155
160
  if (!result.success) {
156
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,
@@ -3,7 +3,6 @@ import { NextAuthErrorCode } from '../types';
3
3
  import { findMatchingIdentity } from './findMatchingIdentity';
4
4
 
5
5
  export async function validateNextAuth(
6
- list: any,
7
6
  identityField: string,
8
7
  identity: string | number,
9
8
  protectIdentities: boolean,
@@ -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,27 +76,30 @@ export default function NextAuthPage(props: NextAuthPageProps) {
75
76
 
76
77
  if (!result.success) {
77
78
  if (!autoCreate) {
78
- console.log('False');
79
+ console.log(
80
+ '`autoCreate` if set to `false`, skipping user auto-creation'
81
+ );
79
82
  return false;
80
83
  }
81
- console.log('Create User');
84
+ console.log(
85
+ '`autoCreate` if set to `true`, auto-creating a new user'
86
+ );
82
87
 
83
- await list
88
+ const createUser = await list
84
89
  .createOne({ data })
85
90
  .then((returned) => {
86
- console.log(returned);
87
-
91
+ console.log('User Created', JSON.stringify(returned));
88
92
  return true;
89
93
  })
90
94
  .catch((error) => {
91
95
  console.log(error);
92
-
93
96
  throw new Error(error);
94
97
  });
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
  }
101
+ // await list.updateOne({where: {id: result.item.id}, data});
102
+ return result.success;
99
103
  },
100
104
  async redirect({ url }) {
101
105
  return url;
@@ -111,10 +115,9 @@ export default function NextAuthPage(props: NextAuthPageProps) {
111
115
  return returnSession;
112
116
  },
113
117
  async jwt({ token }) {
114
- const identity = token.sub;
118
+ const identity = token.sub as number | string;
115
119
  if (!token.itemId) {
116
120
  const result = await validateNextAuth(
117
- list,
118
121
  identityField,
119
122
  identity,
120
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 = [Provider];
15
+ export type NextAuthProviders = Provider[];
16
16
 
17
17
  type KeytoneAuthProviders = {
18
18
  providers: NextAuthProviders;