@opensaas/keystone-nextjs-auth 26.0.0 → 27.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.
@@ -6,21 +6,18 @@ async function findMatchingIdentity(identityField, identity, queryAPI) {
6
6
  where: {
7
7
  [identityField]: identity
8
8
  }
9
- }); // Identity failures with helpful errors
10
-
9
+ });
10
+ // Identity failures with helpful errors
11
11
  let code;
12
-
13
12
  if (!item) {
14
13
  code = 'IDENTITY_NOT_FOUND';
15
14
  }
16
-
17
15
  if (code) {
18
16
  return {
19
17
  success: false,
20
18
  code
21
19
  };
22
20
  }
23
-
24
21
  return {
25
22
  success: true,
26
23
  item
@@ -32,14 +29,12 @@ async function validateNextAuth(identityField, identity, protectIdentities, item
32
29
  const {
33
30
  item
34
31
  } = match;
35
-
36
32
  if (item) {
37
33
  return {
38
34
  success: true,
39
35
  item
40
36
  };
41
37
  }
42
-
43
38
  return {
44
39
  success: false,
45
40
  code: protectIdentities ? 'FAILURE' : 'SUBJECT_NOT_FOUND'
@@ -61,17 +56,14 @@ function NextAuthPage(props) {
61
56
  sessionData,
62
57
  sessionSecret
63
58
  } = props;
64
-
65
59
  if (!query) {
66
60
  console.error('NextAuthPage got no query.');
67
61
  return null;
68
62
  }
69
-
70
63
  if (!providers || !providers.length) {
71
64
  console.error('You need to provide at least one provider.');
72
65
  return null;
73
66
  }
74
-
75
67
  const list = query[listKey];
76
68
  const protectIdentities = true;
77
69
  return NextAuth({
@@ -89,7 +81,6 @@ function NextAuthPage(props) {
89
81
  profile
90
82
  } = _ref;
91
83
  let identity;
92
-
93
84
  if (typeof user.id === 'string') {
94
85
  identity = user.id;
95
86
  } else if (typeof user.id === 'number') {
@@ -97,23 +88,20 @@ function NextAuthPage(props) {
97
88
  } else {
98
89
  identity = 0;
99
90
  }
100
-
101
91
  const userInput = resolver ? await resolver({
102
92
  user,
103
93
  account,
104
94
  profile
105
95
  }) : {};
106
- const result = await validateNextAuth(identityField, identity, protectIdentities, list); // ID
107
-
96
+ const result = await validateNextAuth(identityField, identity, protectIdentities, list);
97
+ // ID
108
98
  const data = _objectSpread({
109
99
  [identityField]: identity
110
100
  }, userInput);
111
-
112
101
  if (!result.success) {
113
102
  if (!autoCreate) {
114
103
  return false;
115
104
  }
116
-
117
105
  const createUser = await list.createOne({
118
106
  data
119
107
  }).then(returned => {
@@ -127,7 +115,6 @@ function NextAuthPage(props) {
127
115
  });
128
116
  return createUser.success;
129
117
  }
130
-
131
118
  const updateUser = await list.updateOne({
132
119
  where: {
133
120
  id: result.item.id
@@ -144,21 +131,18 @@ function NextAuthPage(props) {
144
131
  });
145
132
  return updateUser.success;
146
133
  },
147
-
148
134
  async redirect(_ref2) {
149
135
  let {
150
136
  url
151
137
  } = _ref2;
152
138
  return url;
153
139
  },
154
-
155
140
  async session(_ref3) {
156
141
  let {
157
142
  session,
158
143
  token
159
144
  } = _ref3;
160
145
  let returnSession = session;
161
-
162
146
  if (!token.itemId) {
163
147
  return session;
164
148
  } else {
@@ -169,22 +153,17 @@ function NextAuthPage(props) {
169
153
  itemId: token.itemId
170
154
  });
171
155
  }
172
-
173
156
  return returnSession;
174
157
  },
175
-
176
158
  async jwt(_ref4) {
177
159
  let {
178
160
  token
179
161
  } = _ref4;
180
162
  const identity = token.sub;
181
-
182
163
  if (!identity) {
183
164
  return token;
184
165
  }
185
-
186
166
  const result = await validateNextAuth(identityField, identity, protectIdentities, list);
187
-
188
167
  if (!result.success) {
189
168
  token.itemId = undefined;
190
169
  } else {
@@ -197,15 +176,12 @@ function NextAuthPage(props) {
197
176
  });
198
177
  token.data = data;
199
178
  }
200
-
201
179
  const returnToken = _objectSpread(_objectSpread({}, token), {}, {
202
180
  subject: token.sub,
203
181
  listKey
204
182
  });
205
-
206
183
  return returnToken;
207
184
  }
208
-
209
185
  }
210
186
  });
211
187
  }
package/src/index.ts CHANGED
@@ -61,12 +61,12 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
61
61
  */
62
62
  const authMiddleware: AdminUIConfig<BaseKeystoneTypeInfo>['pageMiddleware'] = async ({
63
63
  context,
64
- isValidSession,
64
+ wasAccessAllowed,
65
65
  }) => {
66
66
  const { req, session } = context;
67
67
  const pathname = url.parse(req?.url!).pathname!;
68
68
 
69
- if (isValidSession) {
69
+ if (wasAccessAllowed) {
70
70
  if (customPath !== '' && pathname === '/') {
71
71
  return { kind: 'redirect', to: `${customPath}` };
72
72
  }