naystack 1.7.26 → 1.7.27

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.
@@ -226,7 +226,6 @@ async function massageRequest(req, options) {
226
226
  }
227
227
  return {
228
228
  data: {
229
- email: data.email,
230
229
  password: data.password,
231
230
  ...data
232
231
  }
@@ -277,9 +276,13 @@ var getContext = (req) => {
277
276
  // src/auth/email/routes/delete.ts
278
277
  var getDeleteRoute = (options) => async (req) => {
279
278
  if (options.onLogout) {
280
- const ctx = await getContext(req);
281
- const body = await req.json();
282
- await options.onLogout?.(ctx.userId, body);
279
+ try {
280
+ const ctx = await getContext(req);
281
+ const body = await req.json().catch(() => null);
282
+ await options.onLogout?.(ctx.userId, body);
283
+ } catch (e) {
284
+ console.error(e);
285
+ }
283
286
  }
284
287
  return getTokenizedResponse();
285
288
  };
@@ -290,8 +293,12 @@ var getGetRoute = (options) => async (req) => {
290
293
  const userID = getUserIdFromRefreshToken(refresh);
291
294
  if (userID) {
292
295
  if (options.onRefresh) {
293
- const body = await req.json().catch(() => null);
294
- await options.onRefresh?.(userID, body);
296
+ try {
297
+ const body = await req.json().catch(() => null);
298
+ await options.onRefresh?.(userID, body);
299
+ } catch (e) {
300
+ console.error(e);
301
+ }
295
302
  }
296
303
  return getTokenizedResponse(
297
304
  userID
@@ -321,7 +328,11 @@ var getPostRoute = (options) => async (req) => {
321
328
  });
322
329
  if (newUser) {
323
330
  if (options.onSignUp) {
324
- await options.onSignUp?.(newUser.id, data);
331
+ try {
332
+ await options.onSignUp?.(newUser.id, data);
333
+ } catch (e) {
334
+ console.error(e);
335
+ }
325
336
  }
326
337
  return getTokenizedResponse(
327
338
  newUser.id
@@ -339,7 +350,11 @@ var getPutRoute = (options) => async (req) => {
339
350
  return handleError(400, "A user does not exist", options.onError);
340
351
  if (await verifyUser(user, data.password)) {
341
352
  if (options.onLogin) {
342
- await options.onLogin?.(user.id, data);
353
+ try {
354
+ await options.onLogin?.(user.id, data);
355
+ } catch (e) {
356
+ console.error(e);
357
+ }
343
358
  }
344
359
  return getTokenizedResponse(
345
360
  user.id
@@ -397,7 +412,7 @@ function AuthFetch() {
397
412
  headers: {
398
413
  Cookie: cookie.toString()
399
414
  }
400
- }).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
415
+ }).then((res) => res.text()).catch(() => null);
401
416
  },
402
417
  Component: import_client2.AuthApply
403
418
  }
@@ -187,7 +187,6 @@ async function massageRequest(req, options) {
187
187
  }
188
188
  return {
189
189
  data: {
190
- email: data.email,
191
190
  password: data.password,
192
191
  ...data
193
192
  }
@@ -238,9 +237,13 @@ var getContext = (req) => {
238
237
  // src/auth/email/routes/delete.ts
239
238
  var getDeleteRoute = (options) => async (req) => {
240
239
  if (options.onLogout) {
241
- const ctx = await getContext(req);
242
- const body = await req.json();
243
- await options.onLogout?.(ctx.userId, body);
240
+ try {
241
+ const ctx = await getContext(req);
242
+ const body = await req.json().catch(() => null);
243
+ await options.onLogout?.(ctx.userId, body);
244
+ } catch (e) {
245
+ console.error(e);
246
+ }
244
247
  }
245
248
  return getTokenizedResponse();
246
249
  };
@@ -251,8 +254,12 @@ var getGetRoute = (options) => async (req) => {
251
254
  const userID = getUserIdFromRefreshToken(refresh);
252
255
  if (userID) {
253
256
  if (options.onRefresh) {
254
- const body = await req.json().catch(() => null);
255
- await options.onRefresh?.(userID, body);
257
+ try {
258
+ const body = await req.json().catch(() => null);
259
+ await options.onRefresh?.(userID, body);
260
+ } catch (e) {
261
+ console.error(e);
262
+ }
256
263
  }
257
264
  return getTokenizedResponse(
258
265
  userID
@@ -282,7 +289,11 @@ var getPostRoute = (options) => async (req) => {
282
289
  });
283
290
  if (newUser) {
284
291
  if (options.onSignUp) {
285
- await options.onSignUp?.(newUser.id, data);
292
+ try {
293
+ await options.onSignUp?.(newUser.id, data);
294
+ } catch (e) {
295
+ console.error(e);
296
+ }
286
297
  }
287
298
  return getTokenizedResponse(
288
299
  newUser.id
@@ -300,7 +311,11 @@ var getPutRoute = (options) => async (req) => {
300
311
  return handleError(400, "A user does not exist", options.onError);
301
312
  if (await verifyUser(user, data.password)) {
302
313
  if (options.onLogin) {
303
- await options.onLogin?.(user.id, data);
314
+ try {
315
+ await options.onLogin?.(user.id, data);
316
+ } catch (e) {
317
+ console.error(e);
318
+ }
304
319
  }
305
320
  return getTokenizedResponse(
306
321
  user.id
@@ -362,7 +377,7 @@ function AuthFetch() {
362
377
  headers: {
363
378
  Cookie: cookie.toString()
364
379
  }
365
- }).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
380
+ }).then((res) => res.text()).catch(() => null);
366
381
  },
367
382
  Component: AuthApply
368
383
  }
@@ -135,7 +135,7 @@ function AuthFetch() {
135
135
  headers: {
136
136
  Cookie: cookie.toString()
137
137
  }
138
- }).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
138
+ }).then((res) => res.text()).catch(() => null);
139
139
  },
140
140
  Component: import_client2.AuthApply
141
141
  }
@@ -104,7 +104,7 @@ function AuthFetch() {
104
104
  headers: {
105
105
  Cookie: cookie.toString()
106
106
  }
107
- }).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
107
+ }).then((res) => res.text()).catch(() => null);
108
108
  },
109
109
  Component: AuthApply
110
110
  }
@@ -160,9 +160,13 @@ var getContext = (req) => {
160
160
  // src/auth/email/routes/delete.ts
161
161
  var getDeleteRoute = (options) => async (req) => {
162
162
  if (options.onLogout) {
163
- const ctx = await getContext(req);
164
- const body = await req.json();
165
- await options.onLogout?.(ctx.userId, body);
163
+ try {
164
+ const ctx = await getContext(req);
165
+ const body = await req.json().catch(() => null);
166
+ await options.onLogout?.(ctx.userId, body);
167
+ } catch (e) {
168
+ console.error(e);
169
+ }
166
170
  }
167
171
  return getTokenizedResponse();
168
172
  };
@@ -134,9 +134,13 @@ var getContext = (req) => {
134
134
  // src/auth/email/routes/delete.ts
135
135
  var getDeleteRoute = (options) => async (req) => {
136
136
  if (options.onLogout) {
137
- const ctx = await getContext(req);
138
- const body = await req.json();
139
- await options.onLogout?.(ctx.userId, body);
137
+ try {
138
+ const ctx = await getContext(req);
139
+ const body = await req.json().catch(() => null);
140
+ await options.onLogout?.(ctx.userId, body);
141
+ } catch (e) {
142
+ console.error(e);
143
+ }
140
144
  }
141
145
  return getTokenizedResponse();
142
146
  };
@@ -134,8 +134,12 @@ var getGetRoute = (options) => async (req) => {
134
134
  const userID = getUserIdFromRefreshToken(refresh);
135
135
  if (userID) {
136
136
  if (options.onRefresh) {
137
- const body = await req.json().catch(() => null);
138
- await options.onRefresh?.(userID, body);
137
+ try {
138
+ const body = await req.json().catch(() => null);
139
+ await options.onRefresh?.(userID, body);
140
+ } catch (e) {
141
+ console.error(e);
142
+ }
139
143
  }
140
144
  return getTokenizedResponse(
141
145
  userID
@@ -108,8 +108,12 @@ var getGetRoute = (options) => async (req) => {
108
108
  const userID = getUserIdFromRefreshToken(refresh);
109
109
  if (userID) {
110
110
  if (options.onRefresh) {
111
- const body = await req.json().catch(() => null);
112
- await options.onRefresh?.(userID, body);
111
+ try {
112
+ const body = await req.json().catch(() => null);
113
+ await options.onRefresh?.(userID, body);
114
+ } catch (e) {
115
+ console.error(e);
116
+ }
113
117
  }
114
118
  return getTokenizedResponse(
115
119
  userID
@@ -150,7 +150,6 @@ async function massageRequest(req, options) {
150
150
  }
151
151
  return {
152
152
  data: {
153
- email: data.email,
154
153
  password: data.password,
155
154
  ...data
156
155
  }
@@ -197,7 +196,11 @@ var getPostRoute = (options) => async (req) => {
197
196
  });
198
197
  if (newUser) {
199
198
  if (options.onSignUp) {
200
- await options.onSignUp?.(newUser.id, data);
199
+ try {
200
+ await options.onSignUp?.(newUser.id, data);
201
+ } catch (e) {
202
+ console.error(e);
203
+ }
201
204
  }
202
205
  return getTokenizedResponse(
203
206
  newUser.id
@@ -126,7 +126,6 @@ async function massageRequest(req, options) {
126
126
  }
127
127
  return {
128
128
  data: {
129
- email: data.email,
130
129
  password: data.password,
131
130
  ...data
132
131
  }
@@ -173,7 +172,11 @@ var getPostRoute = (options) => async (req) => {
173
172
  });
174
173
  if (newUser) {
175
174
  if (options.onSignUp) {
176
- await options.onSignUp?.(newUser.id, data);
175
+ try {
176
+ await options.onSignUp?.(newUser.id, data);
177
+ } catch (e) {
178
+ console.error(e);
179
+ }
177
180
  }
178
181
  return getTokenizedResponse(
179
182
  newUser.id
@@ -149,7 +149,6 @@ async function massageRequest(req, options) {
149
149
  }
150
150
  return {
151
151
  data: {
152
- email: data.email,
153
152
  password: data.password,
154
153
  ...data
155
154
  }
@@ -185,7 +184,11 @@ var getPutRoute = (options) => async (req) => {
185
184
  return handleError(400, "A user does not exist", options.onError);
186
185
  if (await verifyUser(user, data.password)) {
187
186
  if (options.onLogin) {
188
- await options.onLogin?.(user.id, data);
187
+ try {
188
+ await options.onLogin?.(user.id, data);
189
+ } catch (e) {
190
+ console.error(e);
191
+ }
189
192
  }
190
193
  return getTokenizedResponse(
191
194
  user.id
@@ -123,7 +123,6 @@ async function massageRequest(req, options) {
123
123
  }
124
124
  return {
125
125
  data: {
126
- email: data.email,
127
126
  password: data.password,
128
127
  ...data
129
128
  }
@@ -159,7 +158,11 @@ var getPutRoute = (options) => async (req) => {
159
158
  return handleError(400, "A user does not exist", options.onError);
160
159
  if (await verifyUser(user, data.password)) {
161
160
  if (options.onLogin) {
162
- await options.onLogin?.(user.id, data);
161
+ try {
162
+ await options.onLogin?.(user.id, data);
163
+ } catch (e) {
164
+ console.error(e);
165
+ }
163
166
  }
164
167
  return getTokenizedResponse(
165
168
  user.id
@@ -28,10 +28,10 @@ type SetupEmailAuthOptions = {
28
28
  getUser: (data: any) => Promise<UserOutput | undefined>;
29
29
  createUser: (user: any) => Promise<UserOutput | undefined>;
30
30
  onError?: ErrorHandler;
31
- onSignUp?: (userId: number | null, body: any) => Promise<void>;
32
- onLogin?: (userId: number | null, body: any) => Promise<void>;
33
- onRefresh?: (userId: number | null, body: any) => Promise<void>;
34
- onLogout?: (userId: number | null, body: any) => Promise<void>;
31
+ onSignUp?: (userId: number | null, body: object) => Promise<void>;
32
+ onLogin?: (userId: number | null, body: object) => Promise<void>;
33
+ onRefresh?: (userId: number | null, body: object) => Promise<void>;
34
+ onLogout?: (userId: number | null, body: object) => Promise<void>;
35
35
  allowedOrigins?: string[];
36
36
  };
37
37
 
@@ -28,10 +28,10 @@ type SetupEmailAuthOptions = {
28
28
  getUser: (data: any) => Promise<UserOutput | undefined>;
29
29
  createUser: (user: any) => Promise<UserOutput | undefined>;
30
30
  onError?: ErrorHandler;
31
- onSignUp?: (userId: number | null, body: any) => Promise<void>;
32
- onLogin?: (userId: number | null, body: any) => Promise<void>;
33
- onRefresh?: (userId: number | null, body: any) => Promise<void>;
34
- onLogout?: (userId: number | null, body: any) => Promise<void>;
31
+ onSignUp?: (userId: number | null, body: object) => Promise<void>;
32
+ onLogin?: (userId: number | null, body: object) => Promise<void>;
33
+ onRefresh?: (userId: number | null, body: object) => Promise<void>;
34
+ onLogout?: (userId: number | null, body: object) => Promise<void>;
35
35
  allowedOrigins?: string[];
36
36
  };
37
37
 
@@ -129,7 +129,6 @@ async function massageRequest(req, options) {
129
129
  }
130
130
  return {
131
131
  data: {
132
- email: data.email,
133
132
  password: data.password,
134
133
  ...data
135
134
  }
@@ -103,7 +103,6 @@ async function massageRequest(req, options) {
103
103
  }
104
104
  return {
105
105
  data: {
106
- email: data.email,
107
106
  password: data.password,
108
107
  ...data
109
108
  }
@@ -244,7 +244,6 @@ async function massageRequest(req, options) {
244
244
  }
245
245
  return {
246
246
  data: {
247
- email: data.email,
248
247
  password: data.password,
249
248
  ...data
250
249
  }
@@ -295,9 +294,13 @@ var getContext = (req) => {
295
294
  // src/auth/email/routes/delete.ts
296
295
  var getDeleteRoute = (options) => async (req) => {
297
296
  if (options.onLogout) {
298
- const ctx = await getContext(req);
299
- const body = await req.json();
300
- await options.onLogout?.(ctx.userId, body);
297
+ try {
298
+ const ctx = await getContext(req);
299
+ const body = await req.json().catch(() => null);
300
+ await options.onLogout?.(ctx.userId, body);
301
+ } catch (e) {
302
+ console.error(e);
303
+ }
301
304
  }
302
305
  return getTokenizedResponse();
303
306
  };
@@ -308,8 +311,12 @@ var getGetRoute = (options) => async (req) => {
308
311
  const userID = getUserIdFromRefreshToken(refresh);
309
312
  if (userID) {
310
313
  if (options.onRefresh) {
311
- const body = await req.json().catch(() => null);
312
- await options.onRefresh?.(userID, body);
314
+ try {
315
+ const body = await req.json().catch(() => null);
316
+ await options.onRefresh?.(userID, body);
317
+ } catch (e) {
318
+ console.error(e);
319
+ }
313
320
  }
314
321
  return getTokenizedResponse(
315
322
  userID
@@ -339,7 +346,11 @@ var getPostRoute = (options) => async (req) => {
339
346
  });
340
347
  if (newUser) {
341
348
  if (options.onSignUp) {
342
- await options.onSignUp?.(newUser.id, data);
349
+ try {
350
+ await options.onSignUp?.(newUser.id, data);
351
+ } catch (e) {
352
+ console.error(e);
353
+ }
343
354
  }
344
355
  return getTokenizedResponse(
345
356
  newUser.id
@@ -357,7 +368,11 @@ var getPutRoute = (options) => async (req) => {
357
368
  return handleError(400, "A user does not exist", options.onError);
358
369
  if (await verifyUser(user, data.password)) {
359
370
  if (options.onLogin) {
360
- await options.onLogin?.(user.id, data);
371
+ try {
372
+ await options.onLogin?.(user.id, data);
373
+ } catch (e) {
374
+ console.error(e);
375
+ }
361
376
  }
362
377
  return getTokenizedResponse(
363
378
  user.id
@@ -415,7 +430,7 @@ function AuthFetch() {
415
430
  headers: {
416
431
  Cookie: cookie.toString()
417
432
  }
418
- }).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
433
+ }).then((res) => res.text()).catch(() => null);
419
434
  },
420
435
  Component: import_client2.AuthApply
421
436
  }
@@ -199,7 +199,6 @@ async function massageRequest(req, options) {
199
199
  }
200
200
  return {
201
201
  data: {
202
- email: data.email,
203
202
  password: data.password,
204
203
  ...data
205
204
  }
@@ -250,9 +249,13 @@ var getContext = (req) => {
250
249
  // src/auth/email/routes/delete.ts
251
250
  var getDeleteRoute = (options) => async (req) => {
252
251
  if (options.onLogout) {
253
- const ctx = await getContext(req);
254
- const body = await req.json();
255
- await options.onLogout?.(ctx.userId, body);
252
+ try {
253
+ const ctx = await getContext(req);
254
+ const body = await req.json().catch(() => null);
255
+ await options.onLogout?.(ctx.userId, body);
256
+ } catch (e) {
257
+ console.error(e);
258
+ }
256
259
  }
257
260
  return getTokenizedResponse();
258
261
  };
@@ -263,8 +266,12 @@ var getGetRoute = (options) => async (req) => {
263
266
  const userID = getUserIdFromRefreshToken(refresh);
264
267
  if (userID) {
265
268
  if (options.onRefresh) {
266
- const body = await req.json().catch(() => null);
267
- await options.onRefresh?.(userID, body);
269
+ try {
270
+ const body = await req.json().catch(() => null);
271
+ await options.onRefresh?.(userID, body);
272
+ } catch (e) {
273
+ console.error(e);
274
+ }
268
275
  }
269
276
  return getTokenizedResponse(
270
277
  userID
@@ -294,7 +301,11 @@ var getPostRoute = (options) => async (req) => {
294
301
  });
295
302
  if (newUser) {
296
303
  if (options.onSignUp) {
297
- await options.onSignUp?.(newUser.id, data);
304
+ try {
305
+ await options.onSignUp?.(newUser.id, data);
306
+ } catch (e) {
307
+ console.error(e);
308
+ }
298
309
  }
299
310
  return getTokenizedResponse(
300
311
  newUser.id
@@ -312,7 +323,11 @@ var getPutRoute = (options) => async (req) => {
312
323
  return handleError(400, "A user does not exist", options.onError);
313
324
  if (await verifyUser(user, data.password)) {
314
325
  if (options.onLogin) {
315
- await options.onLogin?.(user.id, data);
326
+ try {
327
+ await options.onLogin?.(user.id, data);
328
+ } catch (e) {
329
+ console.error(e);
330
+ }
316
331
  }
317
332
  return getTokenizedResponse(
318
333
  user.id
@@ -374,7 +389,7 @@ function AuthFetch() {
374
389
  headers: {
375
390
  Cookie: cookie.toString()
376
391
  }
377
- }).then((res) => res.json()).then((data) => data.accessToken).catch(() => null);
392
+ }).then((res) => res.text()).catch(() => null);
378
393
  },
379
394
  Component: AuthApply
380
395
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naystack",
3
- "version": "1.7.26",
3
+ "version": "1.7.27",
4
4
  "description": "A stack built with Next + GraphQL + S3 + Auth",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",