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.
- package/dist/auth/email/index.cjs.js +6 -4
- package/dist/auth/email/index.esm.js +6 -4
- package/dist/auth/email/routes/delete.cjs.js +2 -1
- package/dist/auth/email/routes/delete.esm.js +2 -1
- package/dist/auth/email/routes/get.cjs.js +2 -1
- package/dist/auth/email/routes/get.esm.js +2 -1
- package/dist/auth/email/routes/post.cjs.js +1 -1
- package/dist/auth/email/routes/post.esm.js +1 -1
- package/dist/auth/email/routes/put.cjs.js +1 -1
- package/dist/auth/email/routes/put.esm.js +1 -1
- package/dist/auth/email/types.d.mts +5 -5
- package/dist/auth/email/types.d.ts +5 -5
- package/dist/auth/index.cjs.js +6 -4
- package/dist/auth/index.esm.js +6 -4
- package/dist/graphql/client.cjs.js +3 -2
- package/dist/graphql/client.d.mts +1 -1
- package/dist/graphql/client.d.ts +1 -1
- package/dist/graphql/client.esm.js +3 -2
- package/package.json +1 -1
|
@@ -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
|
|
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
|
|
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,
|
|
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,
|
|
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
|
|
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
|
|
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,
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
11
|
-
onLogin?: (userId: number | null,
|
|
12
|
-
onRefresh?: (userId: number | null,
|
|
13
|
-
onLogout?: (userId: number | null,
|
|
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,
|
|
11
|
-
onLogin?: (userId: number | null,
|
|
12
|
-
onRefresh?: (userId: number | null,
|
|
13
|
-
onLogout?: (userId: number | null,
|
|
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;
|
package/dist/auth/index.cjs.js
CHANGED
|
@@ -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
|
|
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
|
|
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,
|
|
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,
|
|
251
|
+
await options.onLogin?.(user.id, data);
|
|
250
252
|
}
|
|
251
253
|
return getTokenizedResponse(
|
|
252
254
|
generateAccessToken(user.id, options.keys.signing),
|
package/dist/auth/index.esm.js
CHANGED
|
@@ -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
|
|
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
|
|
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,
|
|
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,
|
|
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
|
-
(
|
|
95
|
-
|
|
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 [(
|
|
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 };
|
package/dist/graphql/client.d.ts
CHANGED
|
@@ -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 [(
|
|
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
|
-
(
|
|
71
|
-
|
|
70
|
+
(input) => mutate({
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
variables: { input },
|
|
72
73
|
context: tokenContext(token)
|
|
73
74
|
}),
|
|
74
75
|
[token]
|