naystack 1.4.5 → 1.4.8

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.
@@ -171,7 +171,8 @@ var getContext = (keys, req) => {
171
171
  var getDeleteRoute = (options) => async (req) => {
172
172
  if (options.onLogout) {
173
173
  const ctx = await getContext(options.keys, req);
174
- await options.onLogout?.(ctx.userId, req);
174
+ const body = await req.json();
175
+ await options.onLogout?.(ctx.userId, body);
175
176
  }
176
177
  return getTokenizedResponse(void 0, "");
177
178
  };
@@ -182,7 +183,8 @@ var getGetRoute = (options) => async (req) => {
182
183
  const userID = getUserIdFromRefreshToken(options.keys.refresh, refresh);
183
184
  if (userID) {
184
185
  if (options.onRefresh) {
185
- await options.onRefresh?.(userID, req);
186
+ const body = await req.json();
187
+ await options.onRefresh?.(userID, body);
186
188
  }
187
189
  return getTokenizedResponse(
188
190
  generateAccessToken(userID, options.keys.signing)
@@ -213,7 +215,7 @@ var getPostRoute = (options) => async (req) => {
213
215
  });
214
216
  if (newUser) {
215
217
  if (options.onSignUp) {
216
- await options.onSignUp?.(newUser.id, req);
218
+ await options.onSignUp?.(newUser.id, data);
217
219
  }
218
220
  return getTokenizedResponse(
219
221
  generateAccessToken(newUser.id, options.keys.signing),
@@ -232,7 +234,7 @@ var getPutRoute = (options) => async (req) => {
232
234
  return handleError(400, "A user does not exist", options.onError);
233
235
  if (await verifyUser(user, data.password)) {
234
236
  if (options.onLogin) {
235
- await options.onLogin?.(user.id, req);
237
+ await options.onLogin?.(user.id, data);
236
238
  }
237
239
  return getTokenizedResponse(
238
240
  generateAccessToken(user.id, options.keys.signing),
@@ -144,7 +144,8 @@ var getContext = (keys, req) => {
144
144
  var getDeleteRoute = (options) => async (req) => {
145
145
  if (options.onLogout) {
146
146
  const ctx = await getContext(options.keys, req);
147
- await options.onLogout?.(ctx.userId, req);
147
+ const body = await req.json();
148
+ await options.onLogout?.(ctx.userId, body);
148
149
  }
149
150
  return getTokenizedResponse(void 0, "");
150
151
  };
@@ -155,7 +156,8 @@ var getGetRoute = (options) => async (req) => {
155
156
  const userID = getUserIdFromRefreshToken(options.keys.refresh, refresh);
156
157
  if (userID) {
157
158
  if (options.onRefresh) {
158
- await options.onRefresh?.(userID, req);
159
+ const body = await req.json();
160
+ await options.onRefresh?.(userID, body);
159
161
  }
160
162
  return getTokenizedResponse(
161
163
  generateAccessToken(userID, options.keys.signing)
@@ -186,7 +188,7 @@ var getPostRoute = (options) => async (req) => {
186
188
  });
187
189
  if (newUser) {
188
190
  if (options.onSignUp) {
189
- await options.onSignUp?.(newUser.id, req);
191
+ await options.onSignUp?.(newUser.id, data);
190
192
  }
191
193
  return getTokenizedResponse(
192
194
  generateAccessToken(newUser.id, options.keys.signing),
@@ -205,7 +207,7 @@ var getPutRoute = (options) => async (req) => {
205
207
  return handleError(400, "A user does not exist", options.onError);
206
208
  if (await verifyUser(user, data.password)) {
207
209
  if (options.onLogin) {
208
- await options.onLogin?.(user.id, req);
210
+ await options.onLogin?.(user.id, data);
209
211
  }
210
212
  return getTokenizedResponse(
211
213
  generateAccessToken(user.id, options.keys.signing),
@@ -102,7 +102,8 @@ var getContext = (keys, req) => {
102
102
  var getDeleteRoute = (options) => async (req) => {
103
103
  if (options.onLogout) {
104
104
  const ctx = await getContext(options.keys, req);
105
- await options.onLogout?.(ctx.userId, req);
105
+ const body = await req.json();
106
+ await options.onLogout?.(ctx.userId, body);
106
107
  }
107
108
  return getTokenizedResponse(void 0, "");
108
109
  };
@@ -76,7 +76,8 @@ var getContext = (keys, req) => {
76
76
  var getDeleteRoute = (options) => async (req) => {
77
77
  if (options.onLogout) {
78
78
  const ctx = await getContext(options.keys, req);
79
- await options.onLogout?.(ctx.userId, req);
79
+ const body = await req.json();
80
+ await options.onLogout?.(ctx.userId, body);
80
81
  }
81
82
  return getTokenizedResponse(void 0, "");
82
83
  };
@@ -78,7 +78,8 @@ var getGetRoute = (options) => async (req) => {
78
78
  const userID = getUserIdFromRefreshToken(options.keys.refresh, refresh);
79
79
  if (userID) {
80
80
  if (options.onRefresh) {
81
- await options.onRefresh?.(userID, req);
81
+ const body = await req.json();
82
+ await options.onRefresh?.(userID, body);
82
83
  }
83
84
  return getTokenizedResponse(
84
85
  generateAccessToken(userID, options.keys.signing)
@@ -52,7 +52,8 @@ var getGetRoute = (options) => async (req) => {
52
52
  const userID = getUserIdFromRefreshToken(options.keys.refresh, refresh);
53
53
  if (userID) {
54
54
  if (options.onRefresh) {
55
- await options.onRefresh?.(userID, req);
55
+ const body = await req.json();
56
+ await options.onRefresh?.(userID, body);
56
57
  }
57
58
  return getTokenizedResponse(
58
59
  generateAccessToken(userID, options.keys.signing)
@@ -146,7 +146,7 @@ var getPostRoute = (options) => async (req) => {
146
146
  });
147
147
  if (newUser) {
148
148
  if (options.onSignUp) {
149
- await options.onSignUp?.(newUser.id, req);
149
+ await options.onSignUp?.(newUser.id, data);
150
150
  }
151
151
  return getTokenizedResponse(
152
152
  generateAccessToken(newUser.id, options.keys.signing),
@@ -122,7 +122,7 @@ var getPostRoute = (options) => async (req) => {
122
122
  });
123
123
  if (newUser) {
124
124
  if (options.onSignUp) {
125
- await options.onSignUp?.(newUser.id, req);
125
+ await options.onSignUp?.(newUser.id, data);
126
126
  }
127
127
  return getTokenizedResponse(
128
128
  generateAccessToken(newUser.id, options.keys.signing),
@@ -133,7 +133,7 @@ var getPutRoute = (options) => async (req) => {
133
133
  return handleError(400, "A user does not exist", options.onError);
134
134
  if (await verifyUser(user, data.password)) {
135
135
  if (options.onLogin) {
136
- await options.onLogin?.(user.id, req);
136
+ await options.onLogin?.(user.id, data);
137
137
  }
138
138
  return getTokenizedResponse(
139
139
  generateAccessToken(user.id, options.keys.signing),
@@ -107,7 +107,7 @@ var getPutRoute = (options) => async (req) => {
107
107
  return handleError(400, "A user does not exist", options.onError);
108
108
  if (await verifyUser(user, data.password)) {
109
109
  if (options.onLogin) {
110
- await options.onLogin?.(user.id, req);
110
+ await options.onLogin?.(user.id, data);
111
111
  }
112
112
  return getTokenizedResponse(
113
113
  generateAccessToken(user.id, options.keys.signing),
@@ -1,5 +1,5 @@
1
- import { NextRequest } from 'next/server';
2
1
  import { UserOutput, ErrorHandler } from '../types.mjs';
2
+ import 'next/server';
3
3
 
4
4
  type InitRoutesOptions = {
5
5
  getUser: (data: any) => Promise<UserOutput | undefined>;
@@ -7,10 +7,10 @@ type InitRoutesOptions = {
7
7
  onError?: ErrorHandler;
8
8
  keys: AuthKeys;
9
9
  turnstileKey?: string;
10
- onSignUp?: (userId: number | null, req: NextRequest) => Promise<void>;
11
- onLogin?: (userId: number | null, req: NextRequest) => Promise<void>;
12
- onRefresh?: (userId: number | null, req: NextRequest) => Promise<void>;
13
- onLogout?: (userId: number | null, req: NextRequest) => Promise<void>;
10
+ onSignUp?: (userId: number | null, body: any) => Promise<void>;
11
+ onLogin?: (userId: number | null, body: any) => Promise<void>;
12
+ onRefresh?: (userId: number | null, body: any) => Promise<void>;
13
+ onLogout?: (userId: number | null, body: any) => Promise<void>;
14
14
  };
15
15
  interface AuthKeys {
16
16
  signing: string;
@@ -1,5 +1,5 @@
1
- import { NextRequest } from 'next/server';
2
1
  import { UserOutput, ErrorHandler } from '../types.js';
2
+ import 'next/server';
3
3
 
4
4
  type InitRoutesOptions = {
5
5
  getUser: (data: any) => Promise<UserOutput | undefined>;
@@ -7,10 +7,10 @@ type InitRoutesOptions = {
7
7
  onError?: ErrorHandler;
8
8
  keys: AuthKeys;
9
9
  turnstileKey?: string;
10
- onSignUp?: (userId: number | null, req: NextRequest) => Promise<void>;
11
- onLogin?: (userId: number | null, req: NextRequest) => Promise<void>;
12
- onRefresh?: (userId: number | null, req: NextRequest) => Promise<void>;
13
- onLogout?: (userId: number | null, req: NextRequest) => Promise<void>;
10
+ onSignUp?: (userId: number | null, body: any) => Promise<void>;
11
+ onLogin?: (userId: number | null, body: any) => Promise<void>;
12
+ onRefresh?: (userId: number | null, body: any) => Promise<void>;
13
+ onLogout?: (userId: number | null, body: any) => Promise<void>;
14
14
  };
15
15
  interface AuthKeys {
16
16
  signing: string;
@@ -185,7 +185,8 @@ var getContext = (keys, req) => {
185
185
  var getDeleteRoute = (options) => async (req) => {
186
186
  if (options.onLogout) {
187
187
  const ctx = await getContext(options.keys, req);
188
- await options.onLogout?.(ctx.userId, req);
188
+ const body = await req.json();
189
+ await options.onLogout?.(ctx.userId, body);
189
190
  }
190
191
  return getTokenizedResponse(void 0, "");
191
192
  };
@@ -196,7 +197,8 @@ var getGetRoute = (options) => async (req) => {
196
197
  const userID = getUserIdFromRefreshToken(options.keys.refresh, refresh);
197
198
  if (userID) {
198
199
  if (options.onRefresh) {
199
- await options.onRefresh?.(userID, req);
200
+ const body = await req.json();
201
+ await options.onRefresh?.(userID, body);
200
202
  }
201
203
  return getTokenizedResponse(
202
204
  generateAccessToken(userID, options.keys.signing)
@@ -227,7 +229,7 @@ var getPostRoute = (options) => async (req) => {
227
229
  });
228
230
  if (newUser) {
229
231
  if (options.onSignUp) {
230
- await options.onSignUp?.(newUser.id, req);
232
+ await options.onSignUp?.(newUser.id, data);
231
233
  }
232
234
  return getTokenizedResponse(
233
235
  generateAccessToken(newUser.id, options.keys.signing),
@@ -246,7 +248,7 @@ var getPutRoute = (options) => async (req) => {
246
248
  return handleError(400, "A user does not exist", options.onError);
247
249
  if (await verifyUser(user, data.password)) {
248
250
  if (options.onLogin) {
249
- await options.onLogin?.(user.id, req);
251
+ await options.onLogin?.(user.id, data);
250
252
  }
251
253
  return getTokenizedResponse(
252
254
  generateAccessToken(user.id, options.keys.signing),
@@ -156,7 +156,8 @@ var getContext = (keys, req) => {
156
156
  var getDeleteRoute = (options) => async (req) => {
157
157
  if (options.onLogout) {
158
158
  const ctx = await getContext(options.keys, req);
159
- await options.onLogout?.(ctx.userId, req);
159
+ const body = await req.json();
160
+ await options.onLogout?.(ctx.userId, body);
160
161
  }
161
162
  return getTokenizedResponse(void 0, "");
162
163
  };
@@ -167,7 +168,8 @@ var getGetRoute = (options) => async (req) => {
167
168
  const userID = getUserIdFromRefreshToken(options.keys.refresh, refresh);
168
169
  if (userID) {
169
170
  if (options.onRefresh) {
170
- await options.onRefresh?.(userID, req);
171
+ const body = await req.json();
172
+ await options.onRefresh?.(userID, body);
171
173
  }
172
174
  return getTokenizedResponse(
173
175
  generateAccessToken(userID, options.keys.signing)
@@ -198,7 +200,7 @@ var getPostRoute = (options) => async (req) => {
198
200
  });
199
201
  if (newUser) {
200
202
  if (options.onSignUp) {
201
- await options.onSignUp?.(newUser.id, req);
203
+ await options.onSignUp?.(newUser.id, data);
202
204
  }
203
205
  return getTokenizedResponse(
204
206
  generateAccessToken(newUser.id, options.keys.signing),
@@ -217,7 +219,7 @@ var getPutRoute = (options) => async (req) => {
217
219
  return handleError(400, "A user does not exist", options.onError);
218
220
  if (await verifyUser(user, data.password)) {
219
221
  if (options.onLogin) {
220
- await options.onLogin?.(user.id, req);
222
+ await options.onLogin?.(user.id, data);
221
223
  }
222
224
  return getTokenizedResponse(
223
225
  generateAccessToken(user.id, options.keys.signing),
@@ -91,8 +91,9 @@ function useAuthMutation(mutation, options) {
91
91
  const token = (0, import_client2.useToken)();
92
92
  const [mutate, result] = (0, import_client.useMutation)(mutation, options);
93
93
  const method = (0, import_react.useCallback)(
94
- (variables) => mutate({
95
- variables,
94
+ (input) => mutate({
95
+ // @ts-ignore
96
+ variables: { input },
96
97
  context: tokenContext(token)
97
98
  }),
98
99
  [token]
@@ -13,6 +13,6 @@ declare const tokenContext: (token?: string | null) => {
13
13
  credentials: string;
14
14
  } | undefined;
15
15
  declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V): readonly [(v?: V) => Promise<_apollo_client.QueryResult<T, V>>, _apollo_client.QueryResult<T, V>];
16
- declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(variables?: V) => Promise<_apollo_client.FetchResult<T>>, _apollo_client.MutationResult<T>];
16
+ declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(input: V["input"]) => Promise<_apollo_client.FetchResult<T>>, _apollo_client.MutationResult<T>];
17
17
 
18
18
  export { getApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
@@ -13,6 +13,6 @@ declare const tokenContext: (token?: string | null) => {
13
13
  credentials: string;
14
14
  } | undefined;
15
15
  declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocumentNode<T, V>, variables?: V): readonly [(v?: V) => Promise<_apollo_client.QueryResult<T, V>>, _apollo_client.QueryResult<T, V>];
16
- declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(variables?: V) => Promise<_apollo_client.FetchResult<T>>, _apollo_client.MutationResult<T>];
16
+ declare function useAuthMutation<T, V extends OperationVariables>(mutation: TypedDocumentNode<T, V>, options?: MutationHookOptions<T, V>): readonly [(input: V["input"]) => Promise<_apollo_client.FetchResult<T>>, _apollo_client.MutationResult<T>];
17
17
 
18
18
  export { getApolloWrapper, tokenContext, useAuthMutation, useAuthQuery };
@@ -67,8 +67,9 @@ function useAuthMutation(mutation, options) {
67
67
  const token = useToken();
68
68
  const [mutate, result] = useMutation(mutation, options);
69
69
  const method = useCallback(
70
- (variables) => mutate({
71
- variables,
70
+ (input) => mutate({
71
+ // @ts-ignore
72
+ variables: { input },
72
73
  context: tokenContext(token)
73
74
  }),
74
75
  [token]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naystack",
3
- "version": "1.4.5",
3
+ "version": "1.4.8",
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",