naystack 1.2.16 → 1.2.17
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 +23 -18
- package/dist/auth/email/index.d.mts +4 -12
- package/dist/auth/email/index.d.ts +4 -12
- package/dist/auth/email/index.esm.js +23 -18
- package/dist/auth/email/routes/delete.cjs.js +45 -1
- package/dist/auth/email/routes/delete.esm.js +45 -1
- package/dist/auth/email/routes/get.cjs.js +6 -2
- package/dist/auth/email/routes/get.d.mts +2 -2
- package/dist/auth/email/routes/get.d.ts +2 -2
- package/dist/auth/email/routes/get.esm.js +6 -2
- package/dist/auth/email/routes/post.cjs.js +3 -1
- package/dist/auth/email/routes/post.esm.js +3 -1
- package/dist/auth/email/routes/put.cjs.js +3 -0
- package/dist/auth/email/routes/put.esm.js +3 -0
- package/dist/auth/email/types.d.mts +5 -3
- package/dist/auth/email/types.d.ts +5 -3
- package/dist/auth/email/utils.cjs.js +8 -8
- package/dist/auth/email/utils.d.mts +3 -5
- package/dist/auth/email/utils.d.ts +3 -5
- package/dist/auth/email/utils.esm.js +7 -7
- package/dist/auth/index.cjs.js +23 -18
- package/dist/auth/index.d.mts +1 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.esm.js +23 -18
- package/dist/file/index.cjs.js +10 -10
- package/dist/file/index.esm.js +10 -10
- package/dist/file/put.cjs.js +10 -10
- package/dist/file/put.esm.js +10 -10
- package/dist/file/setup.cjs.js +10 -10
- package/dist/file/setup.esm.js +10 -10
- package/dist/graphql/types.d.mts +2 -0
- package/dist/graphql/types.d.ts +2 -0
- package/package.json +1 -1
|
@@ -128,42 +128,49 @@ async function verifyCaptcha(token, secret) {
|
|
|
128
128
|
}
|
|
129
129
|
return false;
|
|
130
130
|
}
|
|
131
|
-
var
|
|
131
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
132
132
|
const bearer = req.headers.get("authorization");
|
|
133
133
|
if (!bearer) {
|
|
134
134
|
const refresh = req.cookies.get("refresh")?.value;
|
|
135
135
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
136
|
-
if (userId) return {
|
|
137
|
-
return null;
|
|
136
|
+
if (userId) return { userId, isRefreshID: true };
|
|
137
|
+
return { userId: null };
|
|
138
138
|
}
|
|
139
139
|
const token = bearer.slice(7);
|
|
140
140
|
try {
|
|
141
141
|
const res = (0, import_jsonwebtoken2.verify)(token, signingKey);
|
|
142
142
|
if (typeof res === "string") {
|
|
143
|
-
return null;
|
|
143
|
+
return { userId: null };
|
|
144
144
|
}
|
|
145
145
|
return {
|
|
146
|
-
|
|
146
|
+
userId: res.id
|
|
147
147
|
};
|
|
148
148
|
} catch {
|
|
149
149
|
}
|
|
150
|
-
return null;
|
|
150
|
+
return { userId: null };
|
|
151
151
|
};
|
|
152
152
|
|
|
153
153
|
// src/auth/email/routes/delete.ts
|
|
154
154
|
var getDeleteRoute = (options) => async (req) => {
|
|
155
|
-
if (options.onLogout)
|
|
155
|
+
if (options.onLogout) {
|
|
156
|
+
const ctx = await getContext(options.refreshKey, options.signingKey, req);
|
|
157
|
+
await options.onLogout?.(ctx.userId, req);
|
|
158
|
+
}
|
|
156
159
|
return getTokenizedResponse(void 0, "");
|
|
157
160
|
};
|
|
158
161
|
|
|
159
162
|
// src/auth/email/routes/get.ts
|
|
160
|
-
var getGetRoute = (options) => (req) => {
|
|
163
|
+
var getGetRoute = (options) => async (req) => {
|
|
161
164
|
const refresh = req.cookies.get("refresh")?.value;
|
|
162
165
|
const userID = getUserIdFromRefreshToken(options.refreshKey, refresh);
|
|
163
|
-
if (userID)
|
|
166
|
+
if (userID) {
|
|
167
|
+
if (options.onRefresh) {
|
|
168
|
+
await options.onRefresh?.(userID, req);
|
|
169
|
+
}
|
|
164
170
|
return getTokenizedResponse(
|
|
165
171
|
generateAccessToken(userID, options.signingKey)
|
|
166
172
|
);
|
|
173
|
+
}
|
|
167
174
|
return getTokenizedResponse();
|
|
168
175
|
};
|
|
169
176
|
|
|
@@ -188,7 +195,9 @@ var getPostRoute = (options) => async (req) => {
|
|
|
188
195
|
password: encryptedPassword
|
|
189
196
|
});
|
|
190
197
|
if (newUser) {
|
|
191
|
-
options.onSignUp
|
|
198
|
+
if (options.onSignUp) {
|
|
199
|
+
await options.onSignUp?.(newUser.id, req);
|
|
200
|
+
}
|
|
192
201
|
return getTokenizedResponse(
|
|
193
202
|
generateAccessToken(newUser.id, options.signingKey),
|
|
194
203
|
generateRefreshToken(newUser.id, options.refreshKey)
|
|
@@ -205,6 +214,9 @@ var getPutRoute = (options) => async (req) => {
|
|
|
205
214
|
if (!user)
|
|
206
215
|
return handleError(400, "A user does not exist", options.onError);
|
|
207
216
|
if (await verifyUser(user, data.password)) {
|
|
217
|
+
if (options.onLogin) {
|
|
218
|
+
await options.onLogin?.(user.id, req);
|
|
219
|
+
}
|
|
208
220
|
return getTokenizedResponse(
|
|
209
221
|
generateAccessToken(user.id, options.signingKey),
|
|
210
222
|
generateRefreshToken(user.id, options.refreshKey)
|
|
@@ -220,14 +232,7 @@ function getEmailAuthRoutes(options) {
|
|
|
220
232
|
POST: getPostRoute(options),
|
|
221
233
|
PUT: getPutRoute(options),
|
|
222
234
|
DELETE: getDeleteRoute(options),
|
|
223
|
-
getContext: (req) =>
|
|
224
|
-
const ids = getUserContext(options.refreshKey, options.signingKey, req);
|
|
225
|
-
if (!ids) return { userId: null };
|
|
226
|
-
if (ids.refreshUserID) {
|
|
227
|
-
return { userId: ids.refreshUserID, isRefreshID: true };
|
|
228
|
-
}
|
|
229
|
-
return { userId: ids.accessUserId };
|
|
230
|
-
}
|
|
235
|
+
getContext: (req) => getContext(options.refreshKey, options.signingKey, req)
|
|
231
236
|
};
|
|
232
237
|
}
|
|
233
238
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
2
|
import { NextRequest } from 'next/server';
|
|
3
|
+
import { Context } from '../../graphql/types.mjs';
|
|
3
4
|
import { InitRoutesOptions } from './types.mjs';
|
|
4
5
|
import '../types.mjs';
|
|
5
6
|
|
|
6
7
|
declare function getEmailAuthRoutes(options: InitRoutesOptions): {
|
|
7
|
-
GET: (req: NextRequest) => next_server.NextResponse<{
|
|
8
|
+
GET: (req: NextRequest) => Promise<next_server.NextResponse<{
|
|
8
9
|
accessToken: string | undefined;
|
|
9
10
|
refreshToken: string | undefined;
|
|
10
|
-
}
|
|
11
|
+
}>>;
|
|
11
12
|
POST: (req: NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
|
|
12
13
|
PUT: (req: NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
|
|
13
14
|
DELETE: (req: NextRequest) => Promise<next_server.NextResponse<{
|
|
14
15
|
accessToken: string | undefined;
|
|
15
16
|
refreshToken: string | undefined;
|
|
16
17
|
}>>;
|
|
17
|
-
getContext: (req: NextRequest) =>
|
|
18
|
-
userId: null;
|
|
19
|
-
isRefreshID?: undefined;
|
|
20
|
-
} | {
|
|
21
|
-
userId: number;
|
|
22
|
-
isRefreshID: boolean;
|
|
23
|
-
} | {
|
|
24
|
-
userId: number | undefined;
|
|
25
|
-
isRefreshID?: undefined;
|
|
26
|
-
};
|
|
18
|
+
getContext: (req: NextRequest) => Context;
|
|
27
19
|
};
|
|
28
20
|
|
|
29
21
|
export { getEmailAuthRoutes };
|
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
2
|
import { NextRequest } from 'next/server';
|
|
3
|
+
import { Context } from '../../graphql/types.js';
|
|
3
4
|
import { InitRoutesOptions } from './types.js';
|
|
4
5
|
import '../types.js';
|
|
5
6
|
|
|
6
7
|
declare function getEmailAuthRoutes(options: InitRoutesOptions): {
|
|
7
|
-
GET: (req: NextRequest) => next_server.NextResponse<{
|
|
8
|
+
GET: (req: NextRequest) => Promise<next_server.NextResponse<{
|
|
8
9
|
accessToken: string | undefined;
|
|
9
10
|
refreshToken: string | undefined;
|
|
10
|
-
}
|
|
11
|
+
}>>;
|
|
11
12
|
POST: (req: NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
|
|
12
13
|
PUT: (req: NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
|
|
13
14
|
DELETE: (req: NextRequest) => Promise<next_server.NextResponse<{
|
|
14
15
|
accessToken: string | undefined;
|
|
15
16
|
refreshToken: string | undefined;
|
|
16
17
|
}>>;
|
|
17
|
-
getContext: (req: NextRequest) =>
|
|
18
|
-
userId: null;
|
|
19
|
-
isRefreshID?: undefined;
|
|
20
|
-
} | {
|
|
21
|
-
userId: number;
|
|
22
|
-
isRefreshID: boolean;
|
|
23
|
-
} | {
|
|
24
|
-
userId: number | undefined;
|
|
25
|
-
isRefreshID?: undefined;
|
|
26
|
-
};
|
|
18
|
+
getContext: (req: NextRequest) => Context;
|
|
27
19
|
};
|
|
28
20
|
|
|
29
21
|
export { getEmailAuthRoutes };
|
|
@@ -102,42 +102,49 @@ async function verifyCaptcha(token, secret) {
|
|
|
102
102
|
}
|
|
103
103
|
return false;
|
|
104
104
|
}
|
|
105
|
-
var
|
|
105
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
106
106
|
const bearer = req.headers.get("authorization");
|
|
107
107
|
if (!bearer) {
|
|
108
108
|
const refresh = req.cookies.get("refresh")?.value;
|
|
109
109
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
110
|
-
if (userId) return {
|
|
111
|
-
return null;
|
|
110
|
+
if (userId) return { userId, isRefreshID: true };
|
|
111
|
+
return { userId: null };
|
|
112
112
|
}
|
|
113
113
|
const token = bearer.slice(7);
|
|
114
114
|
try {
|
|
115
115
|
const res = verify2(token, signingKey);
|
|
116
116
|
if (typeof res === "string") {
|
|
117
|
-
return null;
|
|
117
|
+
return { userId: null };
|
|
118
118
|
}
|
|
119
119
|
return {
|
|
120
|
-
|
|
120
|
+
userId: res.id
|
|
121
121
|
};
|
|
122
122
|
} catch {
|
|
123
123
|
}
|
|
124
|
-
return null;
|
|
124
|
+
return { userId: null };
|
|
125
125
|
};
|
|
126
126
|
|
|
127
127
|
// src/auth/email/routes/delete.ts
|
|
128
128
|
var getDeleteRoute = (options) => async (req) => {
|
|
129
|
-
if (options.onLogout)
|
|
129
|
+
if (options.onLogout) {
|
|
130
|
+
const ctx = await getContext(options.refreshKey, options.signingKey, req);
|
|
131
|
+
await options.onLogout?.(ctx.userId, req);
|
|
132
|
+
}
|
|
130
133
|
return getTokenizedResponse(void 0, "");
|
|
131
134
|
};
|
|
132
135
|
|
|
133
136
|
// src/auth/email/routes/get.ts
|
|
134
|
-
var getGetRoute = (options) => (req) => {
|
|
137
|
+
var getGetRoute = (options) => async (req) => {
|
|
135
138
|
const refresh = req.cookies.get("refresh")?.value;
|
|
136
139
|
const userID = getUserIdFromRefreshToken(options.refreshKey, refresh);
|
|
137
|
-
if (userID)
|
|
140
|
+
if (userID) {
|
|
141
|
+
if (options.onRefresh) {
|
|
142
|
+
await options.onRefresh?.(userID, req);
|
|
143
|
+
}
|
|
138
144
|
return getTokenizedResponse(
|
|
139
145
|
generateAccessToken(userID, options.signingKey)
|
|
140
146
|
);
|
|
147
|
+
}
|
|
141
148
|
return getTokenizedResponse();
|
|
142
149
|
};
|
|
143
150
|
|
|
@@ -162,7 +169,9 @@ var getPostRoute = (options) => async (req) => {
|
|
|
162
169
|
password: encryptedPassword
|
|
163
170
|
});
|
|
164
171
|
if (newUser) {
|
|
165
|
-
options.onSignUp
|
|
172
|
+
if (options.onSignUp) {
|
|
173
|
+
await options.onSignUp?.(newUser.id, req);
|
|
174
|
+
}
|
|
166
175
|
return getTokenizedResponse(
|
|
167
176
|
generateAccessToken(newUser.id, options.signingKey),
|
|
168
177
|
generateRefreshToken(newUser.id, options.refreshKey)
|
|
@@ -179,6 +188,9 @@ var getPutRoute = (options) => async (req) => {
|
|
|
179
188
|
if (!user)
|
|
180
189
|
return handleError(400, "A user does not exist", options.onError);
|
|
181
190
|
if (await verifyUser(user, data.password)) {
|
|
191
|
+
if (options.onLogin) {
|
|
192
|
+
await options.onLogin?.(user.id, req);
|
|
193
|
+
}
|
|
182
194
|
return getTokenizedResponse(
|
|
183
195
|
generateAccessToken(user.id, options.signingKey),
|
|
184
196
|
generateRefreshToken(user.id, options.refreshKey)
|
|
@@ -194,14 +206,7 @@ function getEmailAuthRoutes(options) {
|
|
|
194
206
|
POST: getPostRoute(options),
|
|
195
207
|
PUT: getPutRoute(options),
|
|
196
208
|
DELETE: getDeleteRoute(options),
|
|
197
|
-
getContext: (req) =>
|
|
198
|
-
const ids = getUserContext(options.refreshKey, options.signingKey, req);
|
|
199
|
-
if (!ids) return { userId: null };
|
|
200
|
-
if (ids.refreshUserID) {
|
|
201
|
-
return { userId: ids.refreshUserID, isRefreshID: true };
|
|
202
|
-
}
|
|
203
|
-
return { userId: ids.accessUserId };
|
|
204
|
-
}
|
|
209
|
+
getContext: (req) => getContext(options.refreshKey, options.signingKey, req)
|
|
205
210
|
};
|
|
206
211
|
}
|
|
207
212
|
export {
|
|
@@ -49,10 +49,54 @@ function getTokenizedResponse(accessToken, refreshToken) {
|
|
|
49
49
|
}
|
|
50
50
|
return response;
|
|
51
51
|
}
|
|
52
|
+
function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
53
|
+
if (refreshToken)
|
|
54
|
+
try {
|
|
55
|
+
const decoded = (0, import_jsonwebtoken.verify)(refreshToken, refreshKey);
|
|
56
|
+
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
57
|
+
return decoded.id;
|
|
58
|
+
} catch (e) {
|
|
59
|
+
if (!(e instanceof import_jsonwebtoken.JsonWebTokenError)) console.error(e, "errors");
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/auth/email/utils.ts
|
|
66
|
+
var import_jsonwebtoken2 = require("jsonwebtoken");
|
|
67
|
+
|
|
68
|
+
// src/auth/utils/errors.ts
|
|
69
|
+
var import_server2 = require("next/server");
|
|
70
|
+
|
|
71
|
+
// src/auth/email/utils.ts
|
|
72
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
73
|
+
const bearer = req.headers.get("authorization");
|
|
74
|
+
if (!bearer) {
|
|
75
|
+
const refresh = req.cookies.get("refresh")?.value;
|
|
76
|
+
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
77
|
+
if (userId) return { userId, isRefreshID: true };
|
|
78
|
+
return { userId: null };
|
|
79
|
+
}
|
|
80
|
+
const token = bearer.slice(7);
|
|
81
|
+
try {
|
|
82
|
+
const res = (0, import_jsonwebtoken2.verify)(token, signingKey);
|
|
83
|
+
if (typeof res === "string") {
|
|
84
|
+
return { userId: null };
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
userId: res.id
|
|
88
|
+
};
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
return { userId: null };
|
|
92
|
+
};
|
|
52
93
|
|
|
53
94
|
// src/auth/email/routes/delete.ts
|
|
54
95
|
var getDeleteRoute = (options) => async (req) => {
|
|
55
|
-
if (options.onLogout)
|
|
96
|
+
if (options.onLogout) {
|
|
97
|
+
const ctx = await getContext(options.refreshKey, options.signingKey, req);
|
|
98
|
+
await options.onLogout?.(ctx.userId, req);
|
|
99
|
+
}
|
|
56
100
|
return getTokenizedResponse(void 0, "");
|
|
57
101
|
};
|
|
58
102
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -23,10 +23,54 @@ function getTokenizedResponse(accessToken, refreshToken) {
|
|
|
23
23
|
}
|
|
24
24
|
return response;
|
|
25
25
|
}
|
|
26
|
+
function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
27
|
+
if (refreshToken)
|
|
28
|
+
try {
|
|
29
|
+
const decoded = verify(refreshToken, refreshKey);
|
|
30
|
+
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
31
|
+
return decoded.id;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
if (!(e instanceof JsonWebTokenError)) console.error(e, "errors");
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/auth/email/utils.ts
|
|
40
|
+
import { verify as verify2 } from "jsonwebtoken";
|
|
41
|
+
|
|
42
|
+
// src/auth/utils/errors.ts
|
|
43
|
+
import { NextResponse as NextResponse2 } from "next/server";
|
|
44
|
+
|
|
45
|
+
// src/auth/email/utils.ts
|
|
46
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
47
|
+
const bearer = req.headers.get("authorization");
|
|
48
|
+
if (!bearer) {
|
|
49
|
+
const refresh = req.cookies.get("refresh")?.value;
|
|
50
|
+
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
51
|
+
if (userId) return { userId, isRefreshID: true };
|
|
52
|
+
return { userId: null };
|
|
53
|
+
}
|
|
54
|
+
const token = bearer.slice(7);
|
|
55
|
+
try {
|
|
56
|
+
const res = verify2(token, signingKey);
|
|
57
|
+
if (typeof res === "string") {
|
|
58
|
+
return { userId: null };
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
userId: res.id
|
|
62
|
+
};
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
return { userId: null };
|
|
66
|
+
};
|
|
26
67
|
|
|
27
68
|
// src/auth/email/routes/delete.ts
|
|
28
69
|
var getDeleteRoute = (options) => async (req) => {
|
|
29
|
-
if (options.onLogout)
|
|
70
|
+
if (options.onLogout) {
|
|
71
|
+
const ctx = await getContext(options.refreshKey, options.signingKey, req);
|
|
72
|
+
await options.onLogout?.(ctx.userId, req);
|
|
73
|
+
}
|
|
30
74
|
return getTokenizedResponse(void 0, "");
|
|
31
75
|
};
|
|
32
76
|
export {
|
|
@@ -68,13 +68,17 @@ function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
// src/auth/email/routes/get.ts
|
|
71
|
-
var getGetRoute = (options) => (req) => {
|
|
71
|
+
var getGetRoute = (options) => async (req) => {
|
|
72
72
|
const refresh = req.cookies.get("refresh")?.value;
|
|
73
73
|
const userID = getUserIdFromRefreshToken(options.refreshKey, refresh);
|
|
74
|
-
if (userID)
|
|
74
|
+
if (userID) {
|
|
75
|
+
if (options.onRefresh) {
|
|
76
|
+
await options.onRefresh?.(userID, req);
|
|
77
|
+
}
|
|
75
78
|
return getTokenizedResponse(
|
|
76
79
|
generateAccessToken(userID, options.signingKey)
|
|
77
80
|
);
|
|
81
|
+
}
|
|
78
82
|
return getTokenizedResponse();
|
|
79
83
|
};
|
|
80
84
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -3,9 +3,9 @@ import { NextRequest } from 'next/server';
|
|
|
3
3
|
import { InitRoutesOptions } from '../types.mjs';
|
|
4
4
|
import '../../types.mjs';
|
|
5
5
|
|
|
6
|
-
declare const getGetRoute: (options: InitRoutesOptions) => (req: NextRequest) => next_server.NextResponse<{
|
|
6
|
+
declare const getGetRoute: (options: InitRoutesOptions) => (req: NextRequest) => Promise<next_server.NextResponse<{
|
|
7
7
|
accessToken: string | undefined;
|
|
8
8
|
refreshToken: string | undefined;
|
|
9
|
-
}
|
|
9
|
+
}>>;
|
|
10
10
|
|
|
11
11
|
export { getGetRoute };
|
|
@@ -3,9 +3,9 @@ import { NextRequest } from 'next/server';
|
|
|
3
3
|
import { InitRoutesOptions } from '../types.js';
|
|
4
4
|
import '../../types.js';
|
|
5
5
|
|
|
6
|
-
declare const getGetRoute: (options: InitRoutesOptions) => (req: NextRequest) => next_server.NextResponse<{
|
|
6
|
+
declare const getGetRoute: (options: InitRoutesOptions) => (req: NextRequest) => Promise<next_server.NextResponse<{
|
|
7
7
|
accessToken: string | undefined;
|
|
8
8
|
refreshToken: string | undefined;
|
|
9
|
-
}
|
|
9
|
+
}>>;
|
|
10
10
|
|
|
11
11
|
export { getGetRoute };
|
|
@@ -42,13 +42,17 @@ function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
// src/auth/email/routes/get.ts
|
|
45
|
-
var getGetRoute = (options) => (req) => {
|
|
45
|
+
var getGetRoute = (options) => async (req) => {
|
|
46
46
|
const refresh = req.cookies.get("refresh")?.value;
|
|
47
47
|
const userID = getUserIdFromRefreshToken(options.refreshKey, refresh);
|
|
48
|
-
if (userID)
|
|
48
|
+
if (userID) {
|
|
49
|
+
if (options.onRefresh) {
|
|
50
|
+
await options.onRefresh?.(userID, req);
|
|
51
|
+
}
|
|
49
52
|
return getTokenizedResponse(
|
|
50
53
|
generateAccessToken(userID, options.signingKey)
|
|
51
54
|
);
|
|
55
|
+
}
|
|
52
56
|
return getTokenizedResponse();
|
|
53
57
|
};
|
|
54
58
|
export {
|
|
@@ -136,7 +136,9 @@ var getPostRoute = (options) => async (req) => {
|
|
|
136
136
|
password: encryptedPassword
|
|
137
137
|
});
|
|
138
138
|
if (newUser) {
|
|
139
|
-
options.onSignUp
|
|
139
|
+
if (options.onSignUp) {
|
|
140
|
+
await options.onSignUp?.(newUser.id, req);
|
|
141
|
+
}
|
|
140
142
|
return getTokenizedResponse(
|
|
141
143
|
generateAccessToken(newUser.id, options.signingKey),
|
|
142
144
|
generateRefreshToken(newUser.id, options.refreshKey)
|
|
@@ -112,7 +112,9 @@ var getPostRoute = (options) => async (req) => {
|
|
|
112
112
|
password: encryptedPassword
|
|
113
113
|
});
|
|
114
114
|
if (newUser) {
|
|
115
|
-
options.onSignUp
|
|
115
|
+
if (options.onSignUp) {
|
|
116
|
+
await options.onSignUp?.(newUser.id, req);
|
|
117
|
+
}
|
|
116
118
|
return getTokenizedResponse(
|
|
117
119
|
generateAccessToken(newUser.id, options.signingKey),
|
|
118
120
|
generateRefreshToken(newUser.id, options.refreshKey)
|
|
@@ -123,6 +123,9 @@ var getPutRoute = (options) => async (req) => {
|
|
|
123
123
|
if (!user)
|
|
124
124
|
return handleError(400, "A user does not exist", options.onError);
|
|
125
125
|
if (await verifyUser(user, data.password)) {
|
|
126
|
+
if (options.onLogin) {
|
|
127
|
+
await options.onLogin?.(user.id, req);
|
|
128
|
+
}
|
|
126
129
|
return getTokenizedResponse(
|
|
127
130
|
generateAccessToken(user.id, options.signingKey),
|
|
128
131
|
generateRefreshToken(user.id, options.refreshKey)
|
|
@@ -97,6 +97,9 @@ var getPutRoute = (options) => async (req) => {
|
|
|
97
97
|
if (!user)
|
|
98
98
|
return handleError(400, "A user does not exist", options.onError);
|
|
99
99
|
if (await verifyUser(user, data.password)) {
|
|
100
|
+
if (options.onLogin) {
|
|
101
|
+
await options.onLogin?.(user.id, req);
|
|
102
|
+
}
|
|
100
103
|
return getTokenizedResponse(
|
|
101
104
|
generateAccessToken(user.id, options.signingKey),
|
|
102
105
|
generateRefreshToken(user.id, options.refreshKey)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
1
2
|
import { UserOutput, UserInput, ErrorHandler } from '../types.mjs';
|
|
2
|
-
import 'next/server';
|
|
3
3
|
|
|
4
4
|
type InitRoutesOptions = {
|
|
5
5
|
getUser: (email: string) => Promise<UserOutput | undefined>;
|
|
@@ -8,8 +8,10 @@ type InitRoutesOptions = {
|
|
|
8
8
|
signingKey: string;
|
|
9
9
|
refreshKey: string;
|
|
10
10
|
turnstileKey?: string;
|
|
11
|
-
onSignUp?: (
|
|
12
|
-
|
|
11
|
+
onSignUp?: (userId: number | null, req: NextRequest) => Promise<void>;
|
|
12
|
+
onLogin?: (userId: number | null, req: NextRequest) => Promise<void>;
|
|
13
|
+
onRefresh?: (userId: number | null, req: NextRequest) => Promise<void>;
|
|
14
|
+
onLogout?: (userId: number | null, req: NextRequest) => Promise<void>;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
export type { InitRoutesOptions };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
1
2
|
import { UserOutput, UserInput, ErrorHandler } from '../types.js';
|
|
2
|
-
import 'next/server';
|
|
3
3
|
|
|
4
4
|
type InitRoutesOptions = {
|
|
5
5
|
getUser: (email: string) => Promise<UserOutput | undefined>;
|
|
@@ -8,8 +8,10 @@ type InitRoutesOptions = {
|
|
|
8
8
|
signingKey: string;
|
|
9
9
|
refreshKey: string;
|
|
10
10
|
turnstileKey?: string;
|
|
11
|
-
onSignUp?: (
|
|
12
|
-
|
|
11
|
+
onSignUp?: (userId: number | null, req: NextRequest) => Promise<void>;
|
|
12
|
+
onLogin?: (userId: number | null, req: NextRequest) => Promise<void>;
|
|
13
|
+
onRefresh?: (userId: number | null, req: NextRequest) => Promise<void>;
|
|
14
|
+
onLogout?: (userId: number | null, req: NextRequest) => Promise<void>;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
export type { InitRoutesOptions };
|
|
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/auth/email/utils.ts
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
|
-
|
|
23
|
+
getContext: () => getContext,
|
|
24
24
|
massageRequest: () => massageRequest,
|
|
25
25
|
verifyCaptcha: () => verifyCaptcha
|
|
26
26
|
});
|
|
@@ -95,30 +95,30 @@ async function verifyCaptcha(token, secret) {
|
|
|
95
95
|
}
|
|
96
96
|
return false;
|
|
97
97
|
}
|
|
98
|
-
var
|
|
98
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
99
99
|
const bearer = req.headers.get("authorization");
|
|
100
100
|
if (!bearer) {
|
|
101
101
|
const refresh = req.cookies.get("refresh")?.value;
|
|
102
102
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
103
|
-
if (userId) return {
|
|
104
|
-
return null;
|
|
103
|
+
if (userId) return { userId, isRefreshID: true };
|
|
104
|
+
return { userId: null };
|
|
105
105
|
}
|
|
106
106
|
const token = bearer.slice(7);
|
|
107
107
|
try {
|
|
108
108
|
const res = (0, import_jsonwebtoken2.verify)(token, signingKey);
|
|
109
109
|
if (typeof res === "string") {
|
|
110
|
-
return null;
|
|
110
|
+
return { userId: null };
|
|
111
111
|
}
|
|
112
112
|
return {
|
|
113
|
-
|
|
113
|
+
userId: res.id
|
|
114
114
|
};
|
|
115
115
|
} catch {
|
|
116
116
|
}
|
|
117
|
-
return null;
|
|
117
|
+
return { userId: null };
|
|
118
118
|
};
|
|
119
119
|
// Annotate the CommonJS export names for ESM import in node:
|
|
120
120
|
0 && (module.exports = {
|
|
121
|
-
|
|
121
|
+
getContext,
|
|
122
122
|
massageRequest,
|
|
123
123
|
verifyCaptcha
|
|
124
124
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { Context } from '../../graphql/types.mjs';
|
|
2
3
|
import { InitRoutesOptions } from './types.mjs';
|
|
3
4
|
import '../types.mjs';
|
|
4
5
|
|
|
@@ -12,9 +13,6 @@ declare function massageRequest(req: NextRequest, options: InitRoutesOptions): P
|
|
|
12
13
|
};
|
|
13
14
|
}>;
|
|
14
15
|
declare function verifyCaptcha(token: string, secret?: string): Promise<boolean>;
|
|
15
|
-
declare const
|
|
16
|
-
refreshUserID?: number;
|
|
17
|
-
accessUserId?: number;
|
|
18
|
-
} | null;
|
|
16
|
+
declare const getContext: (refreshKey: string, signingKey: string, req: NextRequest) => Context;
|
|
19
17
|
|
|
20
|
-
export {
|
|
18
|
+
export { getContext, massageRequest, verifyCaptcha };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { Context } from '../../graphql/types.js';
|
|
2
3
|
import { InitRoutesOptions } from './types.js';
|
|
3
4
|
import '../types.js';
|
|
4
5
|
|
|
@@ -12,9 +13,6 @@ declare function massageRequest(req: NextRequest, options: InitRoutesOptions): P
|
|
|
12
13
|
};
|
|
13
14
|
}>;
|
|
14
15
|
declare function verifyCaptcha(token: string, secret?: string): Promise<boolean>;
|
|
15
|
-
declare const
|
|
16
|
-
refreshUserID?: number;
|
|
17
|
-
accessUserId?: number;
|
|
18
|
-
} | null;
|
|
16
|
+
declare const getContext: (refreshKey: string, signingKey: string, req: NextRequest) => Context;
|
|
19
17
|
|
|
20
|
-
export {
|
|
18
|
+
export { getContext, massageRequest, verifyCaptcha };
|
|
@@ -69,29 +69,29 @@ async function verifyCaptcha(token, secret) {
|
|
|
69
69
|
}
|
|
70
70
|
return false;
|
|
71
71
|
}
|
|
72
|
-
var
|
|
72
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
73
73
|
const bearer = req.headers.get("authorization");
|
|
74
74
|
if (!bearer) {
|
|
75
75
|
const refresh = req.cookies.get("refresh")?.value;
|
|
76
76
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
77
|
-
if (userId) return {
|
|
78
|
-
return null;
|
|
77
|
+
if (userId) return { userId, isRefreshID: true };
|
|
78
|
+
return { userId: null };
|
|
79
79
|
}
|
|
80
80
|
const token = bearer.slice(7);
|
|
81
81
|
try {
|
|
82
82
|
const res = verify2(token, signingKey);
|
|
83
83
|
if (typeof res === "string") {
|
|
84
|
-
return null;
|
|
84
|
+
return { userId: null };
|
|
85
85
|
}
|
|
86
86
|
return {
|
|
87
|
-
|
|
87
|
+
userId: res.id
|
|
88
88
|
};
|
|
89
89
|
} catch {
|
|
90
90
|
}
|
|
91
|
-
return null;
|
|
91
|
+
return { userId: null };
|
|
92
92
|
};
|
|
93
93
|
export {
|
|
94
|
-
|
|
94
|
+
getContext,
|
|
95
95
|
massageRequest,
|
|
96
96
|
verifyCaptcha
|
|
97
97
|
};
|
package/dist/auth/index.cjs.js
CHANGED
|
@@ -142,42 +142,49 @@ async function verifyCaptcha(token, secret) {
|
|
|
142
142
|
}
|
|
143
143
|
return false;
|
|
144
144
|
}
|
|
145
|
-
var
|
|
145
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
146
146
|
const bearer = req.headers.get("authorization");
|
|
147
147
|
if (!bearer) {
|
|
148
148
|
const refresh = req.cookies.get("refresh")?.value;
|
|
149
149
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
150
|
-
if (userId) return {
|
|
151
|
-
return null;
|
|
150
|
+
if (userId) return { userId, isRefreshID: true };
|
|
151
|
+
return { userId: null };
|
|
152
152
|
}
|
|
153
153
|
const token = bearer.slice(7);
|
|
154
154
|
try {
|
|
155
155
|
const res = (0, import_jsonwebtoken2.verify)(token, signingKey);
|
|
156
156
|
if (typeof res === "string") {
|
|
157
|
-
return null;
|
|
157
|
+
return { userId: null };
|
|
158
158
|
}
|
|
159
159
|
return {
|
|
160
|
-
|
|
160
|
+
userId: res.id
|
|
161
161
|
};
|
|
162
162
|
} catch {
|
|
163
163
|
}
|
|
164
|
-
return null;
|
|
164
|
+
return { userId: null };
|
|
165
165
|
};
|
|
166
166
|
|
|
167
167
|
// src/auth/email/routes/delete.ts
|
|
168
168
|
var getDeleteRoute = (options) => async (req) => {
|
|
169
|
-
if (options.onLogout)
|
|
169
|
+
if (options.onLogout) {
|
|
170
|
+
const ctx = await getContext(options.refreshKey, options.signingKey, req);
|
|
171
|
+
await options.onLogout?.(ctx.userId, req);
|
|
172
|
+
}
|
|
170
173
|
return getTokenizedResponse(void 0, "");
|
|
171
174
|
};
|
|
172
175
|
|
|
173
176
|
// src/auth/email/routes/get.ts
|
|
174
|
-
var getGetRoute = (options) => (req) => {
|
|
177
|
+
var getGetRoute = (options) => async (req) => {
|
|
175
178
|
const refresh = req.cookies.get("refresh")?.value;
|
|
176
179
|
const userID = getUserIdFromRefreshToken(options.refreshKey, refresh);
|
|
177
|
-
if (userID)
|
|
180
|
+
if (userID) {
|
|
181
|
+
if (options.onRefresh) {
|
|
182
|
+
await options.onRefresh?.(userID, req);
|
|
183
|
+
}
|
|
178
184
|
return getTokenizedResponse(
|
|
179
185
|
generateAccessToken(userID, options.signingKey)
|
|
180
186
|
);
|
|
187
|
+
}
|
|
181
188
|
return getTokenizedResponse();
|
|
182
189
|
};
|
|
183
190
|
|
|
@@ -202,7 +209,9 @@ var getPostRoute = (options) => async (req) => {
|
|
|
202
209
|
password: encryptedPassword
|
|
203
210
|
});
|
|
204
211
|
if (newUser) {
|
|
205
|
-
options.onSignUp
|
|
212
|
+
if (options.onSignUp) {
|
|
213
|
+
await options.onSignUp?.(newUser.id, req);
|
|
214
|
+
}
|
|
206
215
|
return getTokenizedResponse(
|
|
207
216
|
generateAccessToken(newUser.id, options.signingKey),
|
|
208
217
|
generateRefreshToken(newUser.id, options.refreshKey)
|
|
@@ -219,6 +228,9 @@ var getPutRoute = (options) => async (req) => {
|
|
|
219
228
|
if (!user)
|
|
220
229
|
return handleError(400, "A user does not exist", options.onError);
|
|
221
230
|
if (await verifyUser(user, data.password)) {
|
|
231
|
+
if (options.onLogin) {
|
|
232
|
+
await options.onLogin?.(user.id, req);
|
|
233
|
+
}
|
|
222
234
|
return getTokenizedResponse(
|
|
223
235
|
generateAccessToken(user.id, options.signingKey),
|
|
224
236
|
generateRefreshToken(user.id, options.refreshKey)
|
|
@@ -234,14 +246,7 @@ function getEmailAuthRoutes(options) {
|
|
|
234
246
|
POST: getPostRoute(options),
|
|
235
247
|
PUT: getPutRoute(options),
|
|
236
248
|
DELETE: getDeleteRoute(options),
|
|
237
|
-
getContext: (req) =>
|
|
238
|
-
const ids = getUserContext(options.refreshKey, options.signingKey, req);
|
|
239
|
-
if (!ids) return { userId: null };
|
|
240
|
-
if (ids.refreshUserID) {
|
|
241
|
-
return { userId: ids.refreshUserID, isRefreshID: true };
|
|
242
|
-
}
|
|
243
|
-
return { userId: ids.accessUserId };
|
|
244
|
-
}
|
|
249
|
+
getContext: (req) => getContext(options.refreshKey, options.signingKey, req)
|
|
245
250
|
};
|
|
246
251
|
}
|
|
247
252
|
|
package/dist/auth/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ export { getEmailAuthRoutes } from './email/index.mjs';
|
|
|
2
2
|
export { initGoogleAuth } from './google/index.mjs';
|
|
3
3
|
export { initInstagramAuth } from './instagram/index.mjs';
|
|
4
4
|
import 'next/server';
|
|
5
|
+
import '../graphql/types.mjs';
|
|
5
6
|
import './email/types.mjs';
|
|
6
7
|
import './types.mjs';
|
|
7
8
|
import 'googleapis';
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { getEmailAuthRoutes } from './email/index.js';
|
|
|
2
2
|
export { initGoogleAuth } from './google/index.js';
|
|
3
3
|
export { initInstagramAuth } from './instagram/index.js';
|
|
4
4
|
import 'next/server';
|
|
5
|
+
import '../graphql/types.js';
|
|
5
6
|
import './email/types.js';
|
|
6
7
|
import './types.js';
|
|
7
8
|
import 'googleapis';
|
package/dist/auth/index.esm.js
CHANGED
|
@@ -114,42 +114,49 @@ async function verifyCaptcha(token, secret) {
|
|
|
114
114
|
}
|
|
115
115
|
return false;
|
|
116
116
|
}
|
|
117
|
-
var
|
|
117
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
118
118
|
const bearer = req.headers.get("authorization");
|
|
119
119
|
if (!bearer) {
|
|
120
120
|
const refresh = req.cookies.get("refresh")?.value;
|
|
121
121
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
122
|
-
if (userId) return {
|
|
123
|
-
return null;
|
|
122
|
+
if (userId) return { userId, isRefreshID: true };
|
|
123
|
+
return { userId: null };
|
|
124
124
|
}
|
|
125
125
|
const token = bearer.slice(7);
|
|
126
126
|
try {
|
|
127
127
|
const res = verify2(token, signingKey);
|
|
128
128
|
if (typeof res === "string") {
|
|
129
|
-
return null;
|
|
129
|
+
return { userId: null };
|
|
130
130
|
}
|
|
131
131
|
return {
|
|
132
|
-
|
|
132
|
+
userId: res.id
|
|
133
133
|
};
|
|
134
134
|
} catch {
|
|
135
135
|
}
|
|
136
|
-
return null;
|
|
136
|
+
return { userId: null };
|
|
137
137
|
};
|
|
138
138
|
|
|
139
139
|
// src/auth/email/routes/delete.ts
|
|
140
140
|
var getDeleteRoute = (options) => async (req) => {
|
|
141
|
-
if (options.onLogout)
|
|
141
|
+
if (options.onLogout) {
|
|
142
|
+
const ctx = await getContext(options.refreshKey, options.signingKey, req);
|
|
143
|
+
await options.onLogout?.(ctx.userId, req);
|
|
144
|
+
}
|
|
142
145
|
return getTokenizedResponse(void 0, "");
|
|
143
146
|
};
|
|
144
147
|
|
|
145
148
|
// src/auth/email/routes/get.ts
|
|
146
|
-
var getGetRoute = (options) => (req) => {
|
|
149
|
+
var getGetRoute = (options) => async (req) => {
|
|
147
150
|
const refresh = req.cookies.get("refresh")?.value;
|
|
148
151
|
const userID = getUserIdFromRefreshToken(options.refreshKey, refresh);
|
|
149
|
-
if (userID)
|
|
152
|
+
if (userID) {
|
|
153
|
+
if (options.onRefresh) {
|
|
154
|
+
await options.onRefresh?.(userID, req);
|
|
155
|
+
}
|
|
150
156
|
return getTokenizedResponse(
|
|
151
157
|
generateAccessToken(userID, options.signingKey)
|
|
152
158
|
);
|
|
159
|
+
}
|
|
153
160
|
return getTokenizedResponse();
|
|
154
161
|
};
|
|
155
162
|
|
|
@@ -174,7 +181,9 @@ var getPostRoute = (options) => async (req) => {
|
|
|
174
181
|
password: encryptedPassword
|
|
175
182
|
});
|
|
176
183
|
if (newUser) {
|
|
177
|
-
options.onSignUp
|
|
184
|
+
if (options.onSignUp) {
|
|
185
|
+
await options.onSignUp?.(newUser.id, req);
|
|
186
|
+
}
|
|
178
187
|
return getTokenizedResponse(
|
|
179
188
|
generateAccessToken(newUser.id, options.signingKey),
|
|
180
189
|
generateRefreshToken(newUser.id, options.refreshKey)
|
|
@@ -191,6 +200,9 @@ var getPutRoute = (options) => async (req) => {
|
|
|
191
200
|
if (!user)
|
|
192
201
|
return handleError(400, "A user does not exist", options.onError);
|
|
193
202
|
if (await verifyUser(user, data.password)) {
|
|
203
|
+
if (options.onLogin) {
|
|
204
|
+
await options.onLogin?.(user.id, req);
|
|
205
|
+
}
|
|
194
206
|
return getTokenizedResponse(
|
|
195
207
|
generateAccessToken(user.id, options.signingKey),
|
|
196
208
|
generateRefreshToken(user.id, options.refreshKey)
|
|
@@ -206,14 +218,7 @@ function getEmailAuthRoutes(options) {
|
|
|
206
218
|
POST: getPostRoute(options),
|
|
207
219
|
PUT: getPutRoute(options),
|
|
208
220
|
DELETE: getDeleteRoute(options),
|
|
209
|
-
getContext: (req) =>
|
|
210
|
-
const ids = getUserContext(options.refreshKey, options.signingKey, req);
|
|
211
|
-
if (!ids) return { userId: null };
|
|
212
|
-
if (ids.refreshUserID) {
|
|
213
|
-
return { userId: ids.refreshUserID, isRefreshID: true };
|
|
214
|
-
}
|
|
215
|
-
return { userId: ids.accessUserId };
|
|
216
|
-
}
|
|
221
|
+
getContext: (req) => getContext(options.refreshKey, options.signingKey, req)
|
|
217
222
|
};
|
|
218
223
|
}
|
|
219
224
|
|
package/dist/file/index.cjs.js
CHANGED
|
@@ -53,26 +53,26 @@ function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
|
53
53
|
var import_server2 = require("next/server");
|
|
54
54
|
|
|
55
55
|
// src/auth/email/utils.ts
|
|
56
|
-
var
|
|
56
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
57
57
|
const bearer = req.headers.get("authorization");
|
|
58
58
|
if (!bearer) {
|
|
59
59
|
const refresh = req.cookies.get("refresh")?.value;
|
|
60
60
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
61
|
-
if (userId) return {
|
|
62
|
-
return null;
|
|
61
|
+
if (userId) return { userId, isRefreshID: true };
|
|
62
|
+
return { userId: null };
|
|
63
63
|
}
|
|
64
64
|
const token = bearer.slice(7);
|
|
65
65
|
try {
|
|
66
66
|
const res = (0, import_jsonwebtoken2.verify)(token, signingKey);
|
|
67
67
|
if (typeof res === "string") {
|
|
68
|
-
return null;
|
|
68
|
+
return { userId: null };
|
|
69
69
|
}
|
|
70
70
|
return {
|
|
71
|
-
|
|
71
|
+
userId: res.id
|
|
72
72
|
};
|
|
73
73
|
} catch {
|
|
74
74
|
}
|
|
75
|
-
return null;
|
|
75
|
+
return { userId: null };
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
// src/file/utils.ts
|
|
@@ -144,8 +144,8 @@ var uploadFile = (client, Bucket) => async (file, key) => {
|
|
|
144
144
|
|
|
145
145
|
// src/file/put.ts
|
|
146
146
|
var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
147
|
-
const ctx =
|
|
148
|
-
if (!ctx?.
|
|
147
|
+
const ctx = getContext(options.refreshKey, options.signingKey, req);
|
|
148
|
+
if (!ctx?.userId || ctx.isRefreshID)
|
|
149
149
|
return import_server3.NextResponse.json({ error: "unauthorized" }, { status: 401 });
|
|
150
150
|
const formData = await req.formData();
|
|
151
151
|
const type = formData.get("type");
|
|
@@ -156,11 +156,11 @@ var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
|
156
156
|
const url = file ? getFileURL(options)(imageKey) : null;
|
|
157
157
|
const handleKeyProcessing = async () => {
|
|
158
158
|
if (file) await uploadFile(client, options.bucket)(file, imageKey);
|
|
159
|
-
if (!type || !ctx.
|
|
159
|
+
if (!type || !ctx.userId || ctx.isRefreshID) return;
|
|
160
160
|
const { deleteURL, response } = await options.processFile({
|
|
161
161
|
url,
|
|
162
162
|
type,
|
|
163
|
-
userId: ctx.
|
|
163
|
+
userId: ctx.userId,
|
|
164
164
|
data: typeof data === "string" ? JSON.parse(data) : void 0
|
|
165
165
|
});
|
|
166
166
|
if (deleteURL) await deleteImage(client, options)(deleteURL);
|
package/dist/file/index.esm.js
CHANGED
|
@@ -27,26 +27,26 @@ function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
|
27
27
|
import { NextResponse as NextResponse2 } from "next/server";
|
|
28
28
|
|
|
29
29
|
// src/auth/email/utils.ts
|
|
30
|
-
var
|
|
30
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
31
31
|
const bearer = req.headers.get("authorization");
|
|
32
32
|
if (!bearer) {
|
|
33
33
|
const refresh = req.cookies.get("refresh")?.value;
|
|
34
34
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
35
|
-
if (userId) return {
|
|
36
|
-
return null;
|
|
35
|
+
if (userId) return { userId, isRefreshID: true };
|
|
36
|
+
return { userId: null };
|
|
37
37
|
}
|
|
38
38
|
const token = bearer.slice(7);
|
|
39
39
|
try {
|
|
40
40
|
const res = verify2(token, signingKey);
|
|
41
41
|
if (typeof res === "string") {
|
|
42
|
-
return null;
|
|
42
|
+
return { userId: null };
|
|
43
43
|
}
|
|
44
44
|
return {
|
|
45
|
-
|
|
45
|
+
userId: res.id
|
|
46
46
|
};
|
|
47
47
|
} catch {
|
|
48
48
|
}
|
|
49
|
-
return null;
|
|
49
|
+
return { userId: null };
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
// src/file/utils.ts
|
|
@@ -122,8 +122,8 @@ var uploadFile = (client, Bucket) => async (file, key) => {
|
|
|
122
122
|
|
|
123
123
|
// src/file/put.ts
|
|
124
124
|
var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
125
|
-
const ctx =
|
|
126
|
-
if (!ctx?.
|
|
125
|
+
const ctx = getContext(options.refreshKey, options.signingKey, req);
|
|
126
|
+
if (!ctx?.userId || ctx.isRefreshID)
|
|
127
127
|
return NextResponse3.json({ error: "unauthorized" }, { status: 401 });
|
|
128
128
|
const formData = await req.formData();
|
|
129
129
|
const type = formData.get("type");
|
|
@@ -134,11 +134,11 @@ var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
|
134
134
|
const url = file ? getFileURL(options)(imageKey) : null;
|
|
135
135
|
const handleKeyProcessing = async () => {
|
|
136
136
|
if (file) await uploadFile(client, options.bucket)(file, imageKey);
|
|
137
|
-
if (!type || !ctx.
|
|
137
|
+
if (!type || !ctx.userId || ctx.isRefreshID) return;
|
|
138
138
|
const { deleteURL, response } = await options.processFile({
|
|
139
139
|
url,
|
|
140
140
|
type,
|
|
141
|
-
userId: ctx.
|
|
141
|
+
userId: ctx.userId,
|
|
142
142
|
data: typeof data === "string" ? JSON.parse(data) : void 0
|
|
143
143
|
});
|
|
144
144
|
if (deleteURL) await deleteImage(client, options)(deleteURL);
|
package/dist/file/put.cjs.js
CHANGED
|
@@ -51,26 +51,26 @@ function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
|
51
51
|
var import_server2 = require("next/server");
|
|
52
52
|
|
|
53
53
|
// src/auth/email/utils.ts
|
|
54
|
-
var
|
|
54
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
55
55
|
const bearer = req.headers.get("authorization");
|
|
56
56
|
if (!bearer) {
|
|
57
57
|
const refresh = req.cookies.get("refresh")?.value;
|
|
58
58
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
59
|
-
if (userId) return {
|
|
60
|
-
return null;
|
|
59
|
+
if (userId) return { userId, isRefreshID: true };
|
|
60
|
+
return { userId: null };
|
|
61
61
|
}
|
|
62
62
|
const token = bearer.slice(7);
|
|
63
63
|
try {
|
|
64
64
|
const res = (0, import_jsonwebtoken2.verify)(token, signingKey);
|
|
65
65
|
if (typeof res === "string") {
|
|
66
|
-
return null;
|
|
66
|
+
return { userId: null };
|
|
67
67
|
}
|
|
68
68
|
return {
|
|
69
|
-
|
|
69
|
+
userId: res.id
|
|
70
70
|
};
|
|
71
71
|
} catch {
|
|
72
72
|
}
|
|
73
|
-
return null;
|
|
73
|
+
return { userId: null };
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
// src/file/utils.ts
|
|
@@ -119,8 +119,8 @@ var uploadFile = (client, Bucket) => async (file, key) => {
|
|
|
119
119
|
|
|
120
120
|
// src/file/put.ts
|
|
121
121
|
var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
122
|
-
const ctx =
|
|
123
|
-
if (!ctx?.
|
|
122
|
+
const ctx = getContext(options.refreshKey, options.signingKey, req);
|
|
123
|
+
if (!ctx?.userId || ctx.isRefreshID)
|
|
124
124
|
return import_server3.NextResponse.json({ error: "unauthorized" }, { status: 401 });
|
|
125
125
|
const formData = await req.formData();
|
|
126
126
|
const type = formData.get("type");
|
|
@@ -131,11 +131,11 @@ var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
|
131
131
|
const url = file ? getFileURL(options)(imageKey) : null;
|
|
132
132
|
const handleKeyProcessing = async () => {
|
|
133
133
|
if (file) await uploadFile(client, options.bucket)(file, imageKey);
|
|
134
|
-
if (!type || !ctx.
|
|
134
|
+
if (!type || !ctx.userId || ctx.isRefreshID) return;
|
|
135
135
|
const { deleteURL, response } = await options.processFile({
|
|
136
136
|
url,
|
|
137
137
|
type,
|
|
138
|
-
userId: ctx.
|
|
138
|
+
userId: ctx.userId,
|
|
139
139
|
data: typeof data === "string" ? JSON.parse(data) : void 0
|
|
140
140
|
});
|
|
141
141
|
if (deleteURL) await deleteImage(client, options)(deleteURL);
|
package/dist/file/put.esm.js
CHANGED
|
@@ -27,26 +27,26 @@ function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
|
27
27
|
import { NextResponse as NextResponse2 } from "next/server";
|
|
28
28
|
|
|
29
29
|
// src/auth/email/utils.ts
|
|
30
|
-
var
|
|
30
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
31
31
|
const bearer = req.headers.get("authorization");
|
|
32
32
|
if (!bearer) {
|
|
33
33
|
const refresh = req.cookies.get("refresh")?.value;
|
|
34
34
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
35
|
-
if (userId) return {
|
|
36
|
-
return null;
|
|
35
|
+
if (userId) return { userId, isRefreshID: true };
|
|
36
|
+
return { userId: null };
|
|
37
37
|
}
|
|
38
38
|
const token = bearer.slice(7);
|
|
39
39
|
try {
|
|
40
40
|
const res = verify2(token, signingKey);
|
|
41
41
|
if (typeof res === "string") {
|
|
42
|
-
return null;
|
|
42
|
+
return { userId: null };
|
|
43
43
|
}
|
|
44
44
|
return {
|
|
45
|
-
|
|
45
|
+
userId: res.id
|
|
46
46
|
};
|
|
47
47
|
} catch {
|
|
48
48
|
}
|
|
49
|
-
return null;
|
|
49
|
+
return { userId: null };
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
// src/file/utils.ts
|
|
@@ -99,8 +99,8 @@ var uploadFile = (client, Bucket) => async (file, key) => {
|
|
|
99
99
|
|
|
100
100
|
// src/file/put.ts
|
|
101
101
|
var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
102
|
-
const ctx =
|
|
103
|
-
if (!ctx?.
|
|
102
|
+
const ctx = getContext(options.refreshKey, options.signingKey, req);
|
|
103
|
+
if (!ctx?.userId || ctx.isRefreshID)
|
|
104
104
|
return NextResponse3.json({ error: "unauthorized" }, { status: 401 });
|
|
105
105
|
const formData = await req.formData();
|
|
106
106
|
const type = formData.get("type");
|
|
@@ -111,11 +111,11 @@ var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
|
111
111
|
const url = file ? getFileURL(options)(imageKey) : null;
|
|
112
112
|
const handleKeyProcessing = async () => {
|
|
113
113
|
if (file) await uploadFile(client, options.bucket)(file, imageKey);
|
|
114
|
-
if (!type || !ctx.
|
|
114
|
+
if (!type || !ctx.userId || ctx.isRefreshID) return;
|
|
115
115
|
const { deleteURL, response } = await options.processFile({
|
|
116
116
|
url,
|
|
117
117
|
type,
|
|
118
|
-
userId: ctx.
|
|
118
|
+
userId: ctx.userId,
|
|
119
119
|
data: typeof data === "string" ? JSON.parse(data) : void 0
|
|
120
120
|
});
|
|
121
121
|
if (deleteURL) await deleteImage(client, options)(deleteURL);
|
package/dist/file/setup.cjs.js
CHANGED
|
@@ -53,26 +53,26 @@ function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
|
53
53
|
var import_server2 = require("next/server");
|
|
54
54
|
|
|
55
55
|
// src/auth/email/utils.ts
|
|
56
|
-
var
|
|
56
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
57
57
|
const bearer = req.headers.get("authorization");
|
|
58
58
|
if (!bearer) {
|
|
59
59
|
const refresh = req.cookies.get("refresh")?.value;
|
|
60
60
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
61
|
-
if (userId) return {
|
|
62
|
-
return null;
|
|
61
|
+
if (userId) return { userId, isRefreshID: true };
|
|
62
|
+
return { userId: null };
|
|
63
63
|
}
|
|
64
64
|
const token = bearer.slice(7);
|
|
65
65
|
try {
|
|
66
66
|
const res = (0, import_jsonwebtoken2.verify)(token, signingKey);
|
|
67
67
|
if (typeof res === "string") {
|
|
68
|
-
return null;
|
|
68
|
+
return { userId: null };
|
|
69
69
|
}
|
|
70
70
|
return {
|
|
71
|
-
|
|
71
|
+
userId: res.id
|
|
72
72
|
};
|
|
73
73
|
} catch {
|
|
74
74
|
}
|
|
75
|
-
return null;
|
|
75
|
+
return { userId: null };
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
// src/file/utils.ts
|
|
@@ -144,8 +144,8 @@ var uploadFile = (client, Bucket) => async (file, key) => {
|
|
|
144
144
|
|
|
145
145
|
// src/file/put.ts
|
|
146
146
|
var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
147
|
-
const ctx =
|
|
148
|
-
if (!ctx?.
|
|
147
|
+
const ctx = getContext(options.refreshKey, options.signingKey, req);
|
|
148
|
+
if (!ctx?.userId || ctx.isRefreshID)
|
|
149
149
|
return import_server3.NextResponse.json({ error: "unauthorized" }, { status: 401 });
|
|
150
150
|
const formData = await req.formData();
|
|
151
151
|
const type = formData.get("type");
|
|
@@ -156,11 +156,11 @@ var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
|
156
156
|
const url = file ? getFileURL(options)(imageKey) : null;
|
|
157
157
|
const handleKeyProcessing = async () => {
|
|
158
158
|
if (file) await uploadFile(client, options.bucket)(file, imageKey);
|
|
159
|
-
if (!type || !ctx.
|
|
159
|
+
if (!type || !ctx.userId || ctx.isRefreshID) return;
|
|
160
160
|
const { deleteURL, response } = await options.processFile({
|
|
161
161
|
url,
|
|
162
162
|
type,
|
|
163
|
-
userId: ctx.
|
|
163
|
+
userId: ctx.userId,
|
|
164
164
|
data: typeof data === "string" ? JSON.parse(data) : void 0
|
|
165
165
|
});
|
|
166
166
|
if (deleteURL) await deleteImage(client, options)(deleteURL);
|
package/dist/file/setup.esm.js
CHANGED
|
@@ -27,26 +27,26 @@ function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
|
27
27
|
import { NextResponse as NextResponse2 } from "next/server";
|
|
28
28
|
|
|
29
29
|
// src/auth/email/utils.ts
|
|
30
|
-
var
|
|
30
|
+
var getContext = (refreshKey, signingKey, req) => {
|
|
31
31
|
const bearer = req.headers.get("authorization");
|
|
32
32
|
if (!bearer) {
|
|
33
33
|
const refresh = req.cookies.get("refresh")?.value;
|
|
34
34
|
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
35
|
-
if (userId) return {
|
|
36
|
-
return null;
|
|
35
|
+
if (userId) return { userId, isRefreshID: true };
|
|
36
|
+
return { userId: null };
|
|
37
37
|
}
|
|
38
38
|
const token = bearer.slice(7);
|
|
39
39
|
try {
|
|
40
40
|
const res = verify2(token, signingKey);
|
|
41
41
|
if (typeof res === "string") {
|
|
42
|
-
return null;
|
|
42
|
+
return { userId: null };
|
|
43
43
|
}
|
|
44
44
|
return {
|
|
45
|
-
|
|
45
|
+
userId: res.id
|
|
46
46
|
};
|
|
47
47
|
} catch {
|
|
48
48
|
}
|
|
49
|
-
return null;
|
|
49
|
+
return { userId: null };
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
// src/file/utils.ts
|
|
@@ -122,8 +122,8 @@ var uploadFile = (client, Bucket) => async (file, key) => {
|
|
|
122
122
|
|
|
123
123
|
// src/file/put.ts
|
|
124
124
|
var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
125
|
-
const ctx =
|
|
126
|
-
if (!ctx?.
|
|
125
|
+
const ctx = getContext(options.refreshKey, options.signingKey, req);
|
|
126
|
+
if (!ctx?.userId || ctx.isRefreshID)
|
|
127
127
|
return NextResponse3.json({ error: "unauthorized" }, { status: 401 });
|
|
128
128
|
const formData = await req.formData();
|
|
129
129
|
const type = formData.get("type");
|
|
@@ -134,11 +134,11 @@ var getFileUploadPutRoute = (options, client) => async (req) => {
|
|
|
134
134
|
const url = file ? getFileURL(options)(imageKey) : null;
|
|
135
135
|
const handleKeyProcessing = async () => {
|
|
136
136
|
if (file) await uploadFile(client, options.bucket)(file, imageKey);
|
|
137
|
-
if (!type || !ctx.
|
|
137
|
+
if (!type || !ctx.userId || ctx.isRefreshID) return;
|
|
138
138
|
const { deleteURL, response } = await options.processFile({
|
|
139
139
|
url,
|
|
140
140
|
type,
|
|
141
|
-
userId: ctx.
|
|
141
|
+
userId: ctx.userId,
|
|
142
142
|
data: typeof data === "string" ? JSON.parse(data) : void 0
|
|
143
143
|
});
|
|
144
144
|
if (deleteURL) await deleteImage(client, options)(deleteURL);
|
package/dist/graphql/types.d.mts
CHANGED
package/dist/graphql/types.d.ts
CHANGED