dn-react-router-toolkit 0.1.12 → 0.2.1
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/apple_auth.d.mts +38 -0
- package/dist/auth/apple_auth.d.ts +38 -0
- package/dist/{auth-kit → auth}/apple_auth.js +31 -18
- package/dist/auth/apple_auth.mjs +63 -0
- package/dist/{auth-kit/repository.d.mts → auth/auth_repository.d.mts} +10 -11
- package/dist/{auth-kit/repository.d.ts → auth/auth_repository.d.ts} +10 -11
- package/dist/{file-kit/repository.js → auth/auth_repository.js} +3 -3
- package/dist/{auth-kit → auth}/auth_service.d.mts +12 -23
- package/dist/{auth-kit → auth}/auth_service.d.ts +12 -23
- package/dist/{auth-kit → auth}/auth_service.js +24 -77
- package/dist/{auth-kit → auth}/auth_service.mjs +24 -77
- package/dist/auth/client/google_login_button.d.mts +7 -0
- package/dist/auth/client/google_login_button.d.ts +7 -0
- package/dist/{auth-kit → auth}/client/google_login_button.js +24 -19
- package/dist/auth/client/google_login_button.mjs +37 -0
- package/dist/auth/client/provider.d.mts +26 -0
- package/dist/auth/client/provider.d.ts +26 -0
- package/dist/auth/client/provider.js +152 -0
- package/dist/auth/client/provider.mjs +116 -0
- package/dist/{auth-kit → auth}/client/redirect_page.js +1 -1
- package/dist/{auth-kit → auth}/client/redirect_page.mjs +1 -1
- package/dist/auth/google_auth.d.mts +33 -0
- package/dist/auth/google_auth.d.ts +33 -0
- package/dist/{auth-kit → auth}/google_auth.js +23 -32
- package/dist/{auth-kit → auth}/google_auth.mjs +22 -31
- package/dist/auth/handlers/find_auth.d.mts +13 -0
- package/dist/auth/handlers/find_auth.d.ts +13 -0
- package/dist/{route/api/auth/route.js → auth/handlers/find_auth.js} +10 -10
- package/dist/{route/api/auth/route.mjs → auth/handlers/find_auth.mjs} +5 -5
- package/dist/auth/handlers/login.d.mts +13 -0
- package/dist/auth/handlers/login.d.ts +13 -0
- package/dist/{route/api/auth/login/route.js → auth/handlers/login.js} +17 -17
- package/dist/{route/api/auth/login/route.mjs → auth/handlers/login.mjs} +12 -12
- package/dist/auth/handlers/login_with_thirdparty.d.mts +15 -0
- package/dist/auth/handlers/login_with_thirdparty.d.ts +15 -0
- package/dist/{route/api/auth/login/[provider]/route.js → auth/handlers/login_with_thirdparty.js} +12 -27
- package/dist/{route/api/auth/login/[provider]/route.mjs → auth/handlers/login_with_thirdparty.mjs} +7 -22
- package/dist/auth/handlers/logout.d.mts +13 -0
- package/dist/auth/handlers/logout.d.ts +13 -0
- package/dist/{route/api/auth/logout/route.js → auth/handlers/logout.js} +15 -11
- package/dist/{route/api/auth/logout/route.mjs → auth/handlers/logout.mjs} +11 -7
- package/dist/auth/handlers/refresh.d.mts +13 -0
- package/dist/auth/handlers/refresh.d.ts +13 -0
- package/dist/{route/api/auth/refresh/route.js → auth/handlers/refresh.js} +12 -12
- package/dist/{route/api/auth/refresh/route.mjs → auth/handlers/refresh.mjs} +7 -7
- package/dist/auth/handlers/request_password_reset.d.mts +10 -0
- package/dist/auth/handlers/request_password_reset.d.ts +10 -0
- package/dist/auth/handlers/request_password_reset.js +87 -0
- package/dist/auth/handlers/request_password_reset.mjs +60 -0
- package/dist/auth/handlers/reset_password.d.mts +10 -0
- package/dist/auth/handlers/reset_password.d.ts +10 -0
- package/dist/auth/handlers/reset_password.js +88 -0
- package/dist/auth/handlers/reset_password.mjs +61 -0
- package/dist/auth/handlers/signup.d.mts +15 -0
- package/dist/auth/handlers/signup.d.ts +15 -0
- package/dist/auth/handlers/signup.js +147 -0
- package/dist/auth/handlers/signup.mjs +112 -0
- package/dist/auth/handlers/signup_with_thirdparty.d.mts +17 -0
- package/dist/auth/handlers/signup_with_thirdparty.d.ts +17 -0
- package/dist/auth/handlers/signup_with_thirdparty.js +123 -0
- package/dist/auth/handlers/signup_with_thirdparty.mjs +98 -0
- package/dist/auth/handlers/thirdparty_auth_callback.d.mts +16 -0
- package/dist/auth/handlers/thirdparty_auth_callback.d.ts +16 -0
- package/dist/{route/auth/callback/[provider]/route.js → auth/handlers/thirdparty_auth_callback.js} +54 -45
- package/dist/{route/auth/callback/[provider]/route.mjs → auth/handlers/thirdparty_auth_callback.mjs} +49 -40
- package/dist/{auth-kit/jwt.d.mts → auth/jwt_manager.d.mts} +11 -1
- package/dist/{auth-kit/jwt.d.ts → auth/jwt_manager.d.ts} +11 -1
- package/dist/{auth-kit/jwt.js → auth/jwt_manager.js} +25 -11
- package/dist/{auth-kit/jwt.mjs → auth/jwt_manager.mjs} +22 -8
- package/dist/auth/kakao_auth.d.mts +27 -0
- package/dist/auth/kakao_auth.d.ts +27 -0
- package/dist/auth/kakao_auth.js +56 -0
- package/dist/auth/kakao_auth.mjs +31 -0
- package/dist/auth/password_recovery.d.mts +34 -0
- package/dist/auth/password_recovery.d.ts +34 -0
- package/dist/auth/password_recovery.js +169 -0
- package/dist/auth/password_recovery.mjs +134 -0
- package/dist/auth/thirdparty_auth.d.mts +41 -0
- package/dist/auth/thirdparty_auth.d.ts +41 -0
- package/dist/{auth-kit/kakao_auth.js → auth/thirdparty_auth.js} +31 -33
- package/dist/{auth-kit/kakao_auth.mjs → auth/thirdparty_auth.mjs} +26 -28
- package/dist/{auth-kit → auth}/with_auth.d.mts +5 -6
- package/dist/{auth-kit → auth}/with_auth.d.ts +5 -6
- package/dist/{auth-kit → auth}/with_auth.js +26 -10
- package/dist/auth/with_auth.mjs +63 -0
- package/dist/date.d.mts +2 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +4 -2
- package/dist/date.mjs +2 -1
- package/dist/{file-kit → file}/cdn.js +1 -1
- package/dist/{file-kit → file}/cdn.mjs +1 -1
- package/dist/{file-kit → file}/client/drop_file_input.js +3 -3
- package/dist/{file-kit → file}/client/drop_file_input.mjs +3 -3
- package/dist/{file-kit → file}/client/file_upload_button.js +1 -1
- package/dist/{file-kit → file}/client/file_upload_button.mjs +1 -1
- package/dist/{file-kit → file}/client/file_uploader.js +3 -3
- package/dist/{file-kit → file}/client/file_uploader.mjs +2 -2
- package/dist/{file-kit → file}/client/format_size.js +1 -1
- package/dist/{file-kit → file}/client/format_size.mjs +1 -1
- package/dist/{file-kit → file}/client/metadata.js +1 -1
- package/dist/{file-kit → file}/client/metadata.mjs +1 -1
- package/dist/{file-kit/repository.d.mts → file/file_repository.d.mts} +4 -4
- package/dist/{file-kit/repository.d.ts → file/file_repository.d.ts} +4 -4
- package/dist/{auth-kit/repository.js → file/file_repository.js} +3 -3
- package/dist/file/file_service.d.mts +32 -0
- package/dist/file/file_service.d.ts +32 -0
- package/dist/{file-kit → file}/file_service.js +27 -21
- package/dist/file/file_service.mjs +41 -0
- package/dist/file/handlers/delete_file.d.mts +17 -0
- package/dist/file/handlers/delete_file.d.ts +17 -0
- package/dist/{route/api/files/[fileId]/route.js → file/handlers/delete_file.js} +15 -15
- package/dist/{route/api/files/[fileId]/route.mjs → file/handlers/delete_file.mjs} +10 -10
- package/dist/file/handlers/upload_file.d.mts +16 -0
- package/dist/file/handlers/upload_file.d.ts +16 -0
- package/dist/{route/api/files/route.js → file/handlers/upload_file.js} +13 -13
- package/dist/{route/api/files/route.mjs → file/handlers/upload_file.mjs} +8 -8
- package/dist/{file-kit → file}/object_storage.d.mts +3 -1
- package/dist/{file-kit → file}/object_storage.d.ts +3 -1
- package/dist/{file-kit → file}/object_storage.js +2 -2
- package/dist/{file-kit → file}/object_storage.mjs +2 -2
- package/dist/{file-kit → file}/responsive_image.d.mts +4 -4
- package/dist/{file-kit → file}/responsive_image.d.ts +4 -4
- package/dist/{file-kit → file}/responsive_image.js +18 -9
- package/dist/{file-kit → file}/responsive_image.mjs +18 -9
- package/dist/{http-kit → http}/index.js +5 -5
- package/dist/{http-kit → http}/index.mjs +1 -1
- package/dist/{http-kit → http}/response.js +1 -1
- package/dist/{http-kit → http}/response.mjs +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +1 -0
- package/dist/route/api.d.mts +17 -25
- package/dist/route/api.d.ts +17 -25
- package/dist/route/api.js +367 -178
- package/dist/route/api.mjs +356 -177
- package/dist/{seo-kit → seo}/seo.js +1 -1
- package/dist/{seo-kit → seo}/seo.mjs +1 -1
- package/package.json +76 -74
- package/dist/auth-kit/apple_auth.d.mts +0 -24
- package/dist/auth-kit/apple_auth.d.ts +0 -24
- package/dist/auth-kit/apple_auth.mjs +0 -50
- package/dist/auth-kit/client/google_login_button.d.mts +0 -9
- package/dist/auth-kit/client/google_login_button.d.ts +0 -9
- package/dist/auth-kit/client/google_login_button.mjs +0 -32
- package/dist/auth-kit/client/logout.d.mts +0 -3
- package/dist/auth-kit/client/logout.d.ts +0 -3
- package/dist/auth-kit/client/logout.js +0 -49
- package/dist/auth-kit/client/logout.mjs +0 -24
- package/dist/auth-kit/google_auth.d.mts +0 -27
- package/dist/auth-kit/google_auth.d.ts +0 -27
- package/dist/auth-kit/kakao_auth.d.mts +0 -24
- package/dist/auth-kit/kakao_auth.d.ts +0 -24
- package/dist/auth-kit/with_auth.mjs +0 -47
- package/dist/file-kit/file_service.d.mts +0 -26
- package/dist/file-kit/file_service.d.ts +0 -26
- package/dist/file-kit/file_service.mjs +0 -35
- package/dist/route/api/auth/login/_provider_/route.d.mts +0 -20
- package/dist/route/api/auth/login/_provider_/route.d.ts +0 -20
- package/dist/route/api/auth/login/route.d.mts +0 -14
- package/dist/route/api/auth/login/route.d.ts +0 -14
- package/dist/route/api/auth/logout/route.d.mts +0 -14
- package/dist/route/api/auth/logout/route.d.ts +0 -14
- package/dist/route/api/auth/refresh/route.d.mts +0 -13
- package/dist/route/api/auth/refresh/route.d.ts +0 -13
- package/dist/route/api/auth/route.d.mts +0 -13
- package/dist/route/api/auth/route.d.ts +0 -13
- package/dist/route/api/files/_fileId_/route.d.mts +0 -17
- package/dist/route/api/files/_fileId_/route.d.ts +0 -17
- package/dist/route/api/files/route.d.mts +0 -16
- package/dist/route/api/files/route.d.ts +0 -16
- package/dist/route/auth/callback/_provider_/route.d.mts +0 -20
- package/dist/route/auth/callback/_provider_/route.d.ts +0 -20
- /package/dist/{auth-kit/repository.mjs → auth/auth_repository.mjs} +0 -0
- /package/dist/{auth-kit → auth}/client/redirect_page.d.mts +0 -0
- /package/dist/{auth-kit → auth}/client/redirect_page.d.ts +0 -0
- /package/dist/{file-kit → file}/cdn.d.mts +0 -0
- /package/dist/{file-kit → file}/cdn.d.ts +0 -0
- /package/dist/{file-kit → file}/client/drop_file_input.d.mts +0 -0
- /package/dist/{file-kit → file}/client/drop_file_input.d.ts +0 -0
- /package/dist/{file-kit → file}/client/file_upload_button.d.mts +0 -0
- /package/dist/{file-kit → file}/client/file_upload_button.d.ts +0 -0
- /package/dist/{file-kit → file}/client/file_uploader.d.mts +0 -0
- /package/dist/{file-kit → file}/client/file_uploader.d.ts +0 -0
- /package/dist/{file-kit → file}/client/format_size.d.mts +0 -0
- /package/dist/{file-kit → file}/client/format_size.d.ts +0 -0
- /package/dist/{file-kit → file}/client/metadata.d.mts +0 -0
- /package/dist/{file-kit → file}/client/metadata.d.ts +0 -0
- /package/dist/{file-kit/repository.mjs → file/file_repository.mjs} +0 -0
- /package/dist/{http-kit → http}/index.d.mts +0 -0
- /package/dist/{http-kit → http}/index.d.ts +0 -0
- /package/dist/{http-kit → http}/response.d.mts +0 -0
- /package/dist/{http-kit → http}/response.d.ts +0 -0
- /package/dist/{seo-kit → seo}/seo.d.mts +0 -0
- /package/dist/{seo-kit → seo}/seo.d.ts +0 -0
package/dist/route/api.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,16 +17,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/route/api.ts
|
|
21
31
|
var api_exports = {};
|
|
22
32
|
__export(api_exports, {
|
|
23
|
-
|
|
33
|
+
createAPIHandler: () => createAPIHandler
|
|
24
34
|
});
|
|
25
35
|
module.exports = __toCommonJS(api_exports);
|
|
26
36
|
|
|
27
|
-
// src/http
|
|
37
|
+
// src/http/response.ts
|
|
28
38
|
var createJsonResponse = (status) => {
|
|
29
39
|
return (data = {}, init) => {
|
|
30
40
|
return Response.json(data, { status, ...init });
|
|
@@ -74,59 +84,68 @@ var INTERNAL_SERVER_ERROR = createException(
|
|
|
74
84
|
"\uC608\uAE30\uCE58 \uBABB\uD55C \uC624\uB958\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4."
|
|
75
85
|
);
|
|
76
86
|
|
|
77
|
-
// src/
|
|
78
|
-
var
|
|
79
|
-
provider
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
GOOGLE_AUTH,
|
|
83
|
-
APPLE_AUTH,
|
|
84
|
-
SITE_ORIGIN
|
|
87
|
+
// src/auth/handlers/thirdparty_auth_callback.tsx
|
|
88
|
+
var thirdpartyAuthCallbackHandler = async (request, {
|
|
89
|
+
provider,
|
|
90
|
+
authService,
|
|
91
|
+
getThirdPartyAuth
|
|
85
92
|
}) => {
|
|
86
93
|
const url = new URL(request.url);
|
|
87
94
|
const code = url.searchParams.get("code");
|
|
88
95
|
if (!code) {
|
|
89
96
|
throw BAD_REQUEST("\uCF54\uB4DC\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
90
97
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
98
|
+
try {
|
|
99
|
+
const { accessToken, refreshToken } = await getThirdPartyAuth(
|
|
100
|
+
provider
|
|
101
|
+
).login(code);
|
|
102
|
+
const [accessTokenSetCookie, refreshTokenSetCookie] = await Promise.all([
|
|
103
|
+
authService.getAccessTokenSetCookie(accessToken),
|
|
104
|
+
authService.getRefreshTokenSetCookie(refreshToken)
|
|
105
|
+
]);
|
|
106
|
+
const headers = new Headers();
|
|
107
|
+
headers.append("Set-Cookie", accessTokenSetCookie);
|
|
108
|
+
headers.append("Set-Cookie", refreshTokenSetCookie);
|
|
109
|
+
const redirectUrl = url.searchParams.get("state") || "/";
|
|
110
|
+
return new Response("Temporary Redirect", {
|
|
111
|
+
status: 307,
|
|
112
|
+
headers: {
|
|
113
|
+
...headers,
|
|
114
|
+
Location: new URL(
|
|
115
|
+
`/r?redirectUrl=${encodeURIComponent(redirectUrl)}`,
|
|
116
|
+
request.url
|
|
117
|
+
).toString()
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (error instanceof Response) {
|
|
122
|
+
if (error.status == 404) {
|
|
123
|
+
const body = await error.json();
|
|
124
|
+
const token = body.token;
|
|
125
|
+
return new Response(
|
|
126
|
+
"Temporary Redirect",
|
|
127
|
+
{
|
|
128
|
+
status: 307,
|
|
129
|
+
headers: {
|
|
130
|
+
Location: new URL(
|
|
131
|
+
`/signup?token=${token}`,
|
|
132
|
+
request.url
|
|
133
|
+
).toString()
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
}
|
|
120
138
|
}
|
|
121
|
-
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
122
141
|
};
|
|
123
142
|
|
|
124
|
-
// src/
|
|
125
|
-
var
|
|
126
|
-
|
|
127
|
-
|
|
143
|
+
// src/file/handlers/upload_file.ts
|
|
144
|
+
var uploadFileHandler = async (request, {
|
|
145
|
+
authService,
|
|
146
|
+
fileService
|
|
128
147
|
}) => {
|
|
129
|
-
const auth = await
|
|
148
|
+
const auth = await authService.verifyOrRefresh(request);
|
|
130
149
|
const { name, type, size, metadata } = await request.json();
|
|
131
150
|
const headers = {
|
|
132
151
|
"Access-Control-Allow-Origin": "*"
|
|
@@ -138,7 +157,7 @@ var fileUploadHandler = async (request, {
|
|
|
138
157
|
return BAD_REQUEST("\uD30C\uC77C \uD0C0\uC785\uC774 \uD544\uC694\uD574\uC694.", { headers });
|
|
139
158
|
}
|
|
140
159
|
try {
|
|
141
|
-
const result = await
|
|
160
|
+
const result = await fileService.generateSignedUrl({
|
|
142
161
|
userId: auth?.userId,
|
|
143
162
|
name,
|
|
144
163
|
type,
|
|
@@ -154,63 +173,48 @@ var fileUploadHandler = async (request, {
|
|
|
154
173
|
}
|
|
155
174
|
};
|
|
156
175
|
|
|
157
|
-
// src/
|
|
158
|
-
var
|
|
159
|
-
|
|
160
|
-
|
|
176
|
+
// src/file/handlers/delete_file.ts
|
|
177
|
+
var deleteFileHandler = async (request, { fileId }, {
|
|
178
|
+
authService,
|
|
179
|
+
fileRepository
|
|
161
180
|
}) => {
|
|
162
|
-
const auth = await
|
|
163
|
-
const file = await
|
|
181
|
+
const auth = await authService.verifyOrRefresh(request);
|
|
182
|
+
const file = await fileRepository.findFileById(fileId);
|
|
164
183
|
const headers = {
|
|
165
184
|
"Access-Control-Allow-Origin": "*"
|
|
166
185
|
};
|
|
167
186
|
if (!file) {
|
|
168
187
|
return NOT_FOUND("\uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.", { headers });
|
|
169
188
|
}
|
|
170
|
-
if (!
|
|
189
|
+
if (!fileRepository.hasPermission(file, auth?.userId)) {
|
|
171
190
|
return FORBIDDEN("\uD30C\uC77C\uC744 \uC0AD\uC81C\uD560 \uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4.", { headers });
|
|
172
191
|
}
|
|
173
|
-
await
|
|
192
|
+
await fileRepository.deleteFile(fileId);
|
|
174
193
|
return NO_CONTENT({ headers });
|
|
175
194
|
};
|
|
176
195
|
|
|
177
|
-
// src/
|
|
178
|
-
var
|
|
179
|
-
const auth = await
|
|
196
|
+
// src/auth/handlers/find_auth.ts
|
|
197
|
+
var findAuthHandler = async (request, { authService }) => {
|
|
198
|
+
const auth = await authService.verifyOrRefresh(request);
|
|
180
199
|
if (!auth) {
|
|
181
200
|
return UNAUTHORIZED();
|
|
182
201
|
}
|
|
183
202
|
return OK(auth);
|
|
184
203
|
};
|
|
185
204
|
|
|
186
|
-
// src/
|
|
187
|
-
var
|
|
188
|
-
provider
|
|
189
|
-
|
|
190
|
-
GOOGLE_AUTH,
|
|
191
|
-
APPLE_AUTH,
|
|
192
|
-
KAKAO_AUTH
|
|
205
|
+
// src/auth/handlers/login_with_thirdparty.ts
|
|
206
|
+
var loginWithThirdPartyHandler = async (request, {
|
|
207
|
+
provider,
|
|
208
|
+
getThirdPartyAuth
|
|
193
209
|
}) => {
|
|
194
210
|
const { code } = await request.json();
|
|
195
211
|
if (!code) {
|
|
196
212
|
return BAD_REQUEST("\uCF54\uB4DC\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
197
213
|
}
|
|
198
|
-
const getThirdPartyAuth = (provider2) => {
|
|
199
|
-
switch (provider2) {
|
|
200
|
-
case "google":
|
|
201
|
-
return GOOGLE_AUTH;
|
|
202
|
-
case "apple":
|
|
203
|
-
return APPLE_AUTH;
|
|
204
|
-
case "kakao":
|
|
205
|
-
return KAKAO_AUTH;
|
|
206
|
-
default:
|
|
207
|
-
throw BAD_REQUEST("\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uC778\uC99D \uC81C\uACF5\uC790\uC785\uB2C8\uB2E4.");
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
214
|
try {
|
|
211
215
|
const { accessToken, refreshToken } = await getThirdPartyAuth(
|
|
212
216
|
provider
|
|
213
|
-
).
|
|
217
|
+
).login(code);
|
|
214
218
|
return CREATED({
|
|
215
219
|
accessToken,
|
|
216
220
|
refreshToken
|
|
@@ -223,26 +227,26 @@ var loginThirdPartyHandler = async (request, {
|
|
|
223
227
|
}
|
|
224
228
|
};
|
|
225
229
|
|
|
226
|
-
// src/
|
|
227
|
-
var
|
|
228
|
-
|
|
229
|
-
JWT_MANAGER
|
|
230
|
+
// src/auth/handlers/login.ts
|
|
231
|
+
var loginHandler = async (request, {
|
|
232
|
+
authService
|
|
230
233
|
}) => {
|
|
231
|
-
const searchParams = new URL(request.url).searchParams;
|
|
232
234
|
const { id, password } = await request.json();
|
|
233
235
|
try {
|
|
234
|
-
const { accessToken, refreshToken } = await
|
|
236
|
+
const { accessToken, refreshToken } = await authService.login({
|
|
235
237
|
id,
|
|
236
238
|
password
|
|
237
239
|
});
|
|
238
|
-
|
|
240
|
+
const searchParams = new URL(request.url).searchParams;
|
|
241
|
+
const type = searchParams.get("type");
|
|
242
|
+
if (type === "json") {
|
|
239
243
|
return CREATED({ accessToken, refreshToken });
|
|
240
244
|
}
|
|
241
245
|
const [accessTokenSetCookie, refreshTokenSetCookie] = await Promise.all([
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
authService.getAccessTokenSetCookie(accessToken),
|
|
247
|
+
authService.getRefreshTokenSetCookie(refreshToken)
|
|
244
248
|
]);
|
|
245
|
-
const payload =
|
|
249
|
+
const payload = authService.jwtManager.decode(accessToken);
|
|
246
250
|
const headers = new Headers();
|
|
247
251
|
headers.append("Set-Cookie", accessTokenSetCookie);
|
|
248
252
|
headers.append("Set-Cookie", refreshTokenSetCookie);
|
|
@@ -257,17 +261,21 @@ var loginCredentialHandler = async (request, {
|
|
|
257
261
|
}
|
|
258
262
|
};
|
|
259
263
|
|
|
260
|
-
// src/
|
|
261
|
-
var logoutHandler = async (request, {
|
|
262
|
-
const auth = await
|
|
264
|
+
// src/auth/handlers/logout.ts
|
|
265
|
+
var logoutHandler = async (request, { authService }) => {
|
|
266
|
+
const auth = await authService.verifyOrRefresh(request);
|
|
263
267
|
if (!auth) {
|
|
264
268
|
return UNAUTHORIZED();
|
|
265
269
|
}
|
|
266
|
-
await
|
|
270
|
+
await authService.authRepository.updateUserRefreshToken(auth.userId, null);
|
|
271
|
+
const type = new URL(request.url).searchParams.get("type");
|
|
272
|
+
if (type === "json") {
|
|
273
|
+
return NO_CONTENT();
|
|
274
|
+
}
|
|
267
275
|
const headers = new Headers();
|
|
268
276
|
const [accessTokenSetCookie, refreshTokenSetCookie] = await Promise.all([
|
|
269
|
-
|
|
270
|
-
|
|
277
|
+
authService.getAccessTokenSetCookie(null),
|
|
278
|
+
authService.getRefreshTokenSetCookie(null)
|
|
271
279
|
]);
|
|
272
280
|
headers.append("Set-Cookie", accessTokenSetCookie);
|
|
273
281
|
headers.append("Set-Cookie", refreshTokenSetCookie);
|
|
@@ -276,16 +284,16 @@ var logoutHandler = async (request, { AUTH, repository }) => {
|
|
|
276
284
|
});
|
|
277
285
|
};
|
|
278
286
|
|
|
279
|
-
// src/
|
|
280
|
-
var
|
|
281
|
-
|
|
287
|
+
// src/auth/handlers/refresh.ts
|
|
288
|
+
var refreshHandler = async (request, {
|
|
289
|
+
authService
|
|
282
290
|
}) => {
|
|
283
|
-
const refreshToken = request?.headers.get("Authorization")?.replace("Bearer ", "") || await
|
|
291
|
+
const refreshToken = request?.headers.get("Authorization")?.replace("Bearer ", "") || await authService.getRefreshTokenFromCookies(request);
|
|
284
292
|
if (!refreshToken) {
|
|
285
293
|
return BAD_REQUEST();
|
|
286
294
|
}
|
|
287
295
|
try {
|
|
288
|
-
const accessToken = await
|
|
296
|
+
const accessToken = await authService.refreshAccessToken(refreshToken);
|
|
289
297
|
return CREATED({ accessToken });
|
|
290
298
|
} catch (e) {
|
|
291
299
|
if (e instanceof Error) {
|
|
@@ -295,101 +303,282 @@ var authRefreshHandler = async (request, {
|
|
|
295
303
|
}
|
|
296
304
|
};
|
|
297
305
|
|
|
298
|
-
// src/
|
|
299
|
-
var
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
KAKAO_AUTH,
|
|
304
|
-
JWT_MANAGER,
|
|
305
|
-
FILE_SERVICE,
|
|
306
|
-
SITE_ORIGIN,
|
|
307
|
-
authRepository,
|
|
306
|
+
// src/auth/handlers/signup.ts
|
|
307
|
+
var import_uuid = require("uuid");
|
|
308
|
+
var bcrypt = __toESM(require("bcryptjs"));
|
|
309
|
+
var signupHandler = async (request, {
|
|
310
|
+
authService,
|
|
308
311
|
fileRepository
|
|
309
312
|
}) => {
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
313
|
+
const body = await request.json();
|
|
314
|
+
const {
|
|
315
|
+
email,
|
|
316
|
+
password,
|
|
317
|
+
passwordConfirm,
|
|
318
|
+
name,
|
|
319
|
+
profileImageId
|
|
320
|
+
} = body;
|
|
321
|
+
if (!email) {
|
|
322
|
+
return BAD_REQUEST("\uC774\uBA54\uC77C\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694.");
|
|
323
|
+
}
|
|
324
|
+
if (!password) {
|
|
325
|
+
return BAD_REQUEST("\uBE44\uBC00\uBC88\uD638\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694.");
|
|
326
|
+
}
|
|
327
|
+
if (!passwordConfirm) {
|
|
328
|
+
return BAD_REQUEST("\uBE44\uBC00\uBC88\uD638 \uD655\uC778\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694.");
|
|
329
|
+
}
|
|
330
|
+
const existing = await authService.authRepository.findCredentialById(email);
|
|
331
|
+
if (existing) {
|
|
332
|
+
return CONFLICT("\uC774\uBBF8 \uAC00\uC785\uD55C \uC774\uBA54\uC77C\uC785\uB2C8\uB2E4.");
|
|
333
|
+
}
|
|
334
|
+
if (password !== passwordConfirm) {
|
|
335
|
+
return BAD_REQUEST("\uBE44\uBC00\uBC88\uD638\uAC00 \uC77C\uCE58\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
|
|
336
|
+
}
|
|
337
|
+
const profileImage = profileImageId ? await fileRepository.findFileById(profileImageId) : void 0;
|
|
338
|
+
const userId = (0, import_uuid.v5)(email, import_uuid.v5.DNS);
|
|
339
|
+
const user = await authService.authRepository.createUser({
|
|
340
|
+
id: userId,
|
|
341
|
+
name,
|
|
342
|
+
role: "user",
|
|
343
|
+
email,
|
|
344
|
+
profileImage
|
|
345
|
+
});
|
|
346
|
+
await authService.authRepository.createCredential({
|
|
347
|
+
id: email,
|
|
348
|
+
userId,
|
|
349
|
+
password: bcrypt.hashSync(password, 10)
|
|
350
|
+
});
|
|
351
|
+
const { accessToken, refreshToken } = await authService.issueTokenPair(user);
|
|
352
|
+
const searchParams = new URL(request.url).searchParams;
|
|
353
|
+
const type = searchParams.get("type");
|
|
354
|
+
if (type === "json") {
|
|
355
|
+
return CREATED({ accessToken, refreshToken });
|
|
356
|
+
}
|
|
357
|
+
const [accessTokenSetCookie, refreshTokenSetCookie] = await Promise.all([
|
|
358
|
+
authService.getAccessTokenSetCookie(accessToken),
|
|
359
|
+
authService.getRefreshTokenSetCookie(refreshToken)
|
|
360
|
+
]);
|
|
361
|
+
const payload = authService.jwtManager.decode(accessToken);
|
|
362
|
+
const headers = new Headers();
|
|
363
|
+
headers.append("Set-Cookie", accessTokenSetCookie);
|
|
364
|
+
headers.append("Set-Cookie", refreshTokenSetCookie);
|
|
365
|
+
return CREATED(payload, {
|
|
366
|
+
headers
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
// src/auth/handlers/signup_with_thirdparty.ts
|
|
371
|
+
var import_uuid2 = require("uuid");
|
|
372
|
+
var signUpWithThirdpartyHandler = async (request, {
|
|
373
|
+
authService,
|
|
374
|
+
fileService,
|
|
375
|
+
signupTokenSecret
|
|
376
|
+
}) => {
|
|
377
|
+
const body = await request.json();
|
|
378
|
+
const {
|
|
379
|
+
token
|
|
380
|
+
} = body;
|
|
381
|
+
const payload = await authService.jwtManager.verify(token, signupTokenSecret);
|
|
382
|
+
const { provider, id: thirdpartyId, email, name, picture } = payload;
|
|
383
|
+
const existing = await authService.authRepository.findThirdPartyAuth(
|
|
384
|
+
provider,
|
|
385
|
+
thirdpartyId
|
|
386
|
+
);
|
|
387
|
+
if (existing) {
|
|
388
|
+
return CONFLICT("\uC774\uBBF8 \uAC00\uC785\uB41C \uC81C3\uC790 \uC778\uC99D \uC815\uBCF4\uC785\uB2C8\uB2E4.");
|
|
389
|
+
}
|
|
390
|
+
const userId = (0, import_uuid2.v5)(thirdpartyId, import_uuid2.v5.DNS);
|
|
391
|
+
const profileImage = await (async () => {
|
|
392
|
+
if (!picture) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
const arrayBuffer = await fetch(picture).then((res) => res.arrayBuffer());
|
|
396
|
+
const { file } = await fileService.putFile(Buffer.from(arrayBuffer), {
|
|
397
|
+
userId,
|
|
398
|
+
name: "profile.jpg",
|
|
399
|
+
type: "image/jpeg",
|
|
400
|
+
size: arrayBuffer.byteLength
|
|
401
|
+
});
|
|
402
|
+
return file;
|
|
403
|
+
})();
|
|
404
|
+
const user = await authService.authRepository.createUser({
|
|
405
|
+
id: userId,
|
|
406
|
+
name,
|
|
407
|
+
role: "user",
|
|
408
|
+
email,
|
|
409
|
+
profileImage
|
|
410
|
+
});
|
|
411
|
+
await authService.authRepository.createThirdPartyAuth({
|
|
412
|
+
id: thirdpartyId,
|
|
413
|
+
provider,
|
|
414
|
+
userId
|
|
415
|
+
});
|
|
416
|
+
const { accessToken, refreshToken } = await authService.issueTokenPair(user);
|
|
417
|
+
return CREATED({ accessToken, refreshToken });
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
// src/auth/handlers/request_password_reset.ts
|
|
421
|
+
var requestPasswordResetHandler = async (request, {
|
|
422
|
+
passwordRecoveryService
|
|
423
|
+
}) => {
|
|
424
|
+
const { email } = await request.json();
|
|
425
|
+
try {
|
|
426
|
+
await passwordRecoveryService.requestPasswordReset(email);
|
|
427
|
+
return CREATED({ message: "\uBE44\uBC00\uBC88\uD638 \uC7AC\uC124\uC815 \uC774\uBA54\uC77C\uC744 \uC804\uC1A1\uD588\uC2B5\uB2C8\uB2E4." });
|
|
428
|
+
} catch (error) {
|
|
429
|
+
console.error(error);
|
|
430
|
+
return INTERNAL_SERVER_ERROR("\uC774\uBA54\uC77C \uC804\uC1A1\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4.");
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
// src/auth/handlers/reset_password.ts
|
|
435
|
+
var resetPasswordHandler = async (request, {
|
|
436
|
+
passwordRecoveryService
|
|
437
|
+
}) => {
|
|
438
|
+
const { token, password, passwordConfirm } = await request.json();
|
|
439
|
+
await passwordRecoveryService.resetPassword(token, password, passwordConfirm);
|
|
440
|
+
return NO_CONTENT();
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
// src/route/api.ts
|
|
444
|
+
var createAPIHandler = ({
|
|
445
|
+
authService,
|
|
446
|
+
fileService,
|
|
447
|
+
passwordRecoveryService,
|
|
448
|
+
getThirdPartyAuth,
|
|
449
|
+
signupTokenSecret
|
|
450
|
+
}) => {
|
|
451
|
+
const handler = async ({ request, params }) => {
|
|
314
452
|
const method = request.method.toUpperCase();
|
|
315
|
-
const slug = params["*"].split("/");
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
if (method === "POST") {
|
|
326
|
-
return loginThirdPartyHandler(
|
|
327
|
-
request,
|
|
328
|
-
{ provider },
|
|
329
|
-
{ GOOGLE_AUTH, KAKAO_AUTH, APPLE_AUTH }
|
|
330
|
-
);
|
|
453
|
+
const slug = params["*"] ? params["*"].split("/") : [];
|
|
454
|
+
switch (slug[0]) {
|
|
455
|
+
case "auth": {
|
|
456
|
+
switch (slug[1]) {
|
|
457
|
+
case void 0: {
|
|
458
|
+
switch (method) {
|
|
459
|
+
case "GET": {
|
|
460
|
+
return findAuthHandler(request, { authService });
|
|
461
|
+
}
|
|
462
|
+
}
|
|
331
463
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
if (slug[1] === "callback") {
|
|
354
|
-
if (slug[2]) {
|
|
355
|
-
const provider = slug[2];
|
|
356
|
-
if (method === "GET") {
|
|
357
|
-
return thirdPartyAuthCallbackHandler(
|
|
358
|
-
request,
|
|
359
|
-
{ provider },
|
|
360
|
-
{
|
|
361
|
-
AUTH,
|
|
362
|
-
GOOGLE_AUTH,
|
|
363
|
-
APPLE_AUTH,
|
|
364
|
-
SITE_ORIGIN
|
|
464
|
+
case "login": {
|
|
465
|
+
switch (slug[2]) {
|
|
466
|
+
case void 0: {
|
|
467
|
+
switch (method) {
|
|
468
|
+
case "POST": {
|
|
469
|
+
return loginHandler(request, {
|
|
470
|
+
authService
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
default: {
|
|
476
|
+
const provider = slug[2];
|
|
477
|
+
switch (method) {
|
|
478
|
+
case "POST": {
|
|
479
|
+
return loginWithThirdPartyHandler(
|
|
480
|
+
request,
|
|
481
|
+
{ provider, getThirdPartyAuth }
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
365
485
|
}
|
|
366
|
-
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
case "logout": {
|
|
489
|
+
switch (method) {
|
|
490
|
+
case "POST": {
|
|
491
|
+
return logoutHandler(request, {
|
|
492
|
+
authService
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
case "refresh": {
|
|
498
|
+
switch (method) {
|
|
499
|
+
case "GET": {
|
|
500
|
+
return refreshHandler(request, { authService });
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
case "signup": {
|
|
505
|
+
switch (slug[2]) {
|
|
506
|
+
case void 0: {
|
|
507
|
+
switch (method) {
|
|
508
|
+
case "POST": {
|
|
509
|
+
return signupHandler(request, {
|
|
510
|
+
authService,
|
|
511
|
+
fileRepository: fileService.fileRepository
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
default: {
|
|
517
|
+
switch (method) {
|
|
518
|
+
case "POST": {
|
|
519
|
+
return signUpWithThirdpartyHandler(
|
|
520
|
+
request,
|
|
521
|
+
{ authService, fileService, signupTokenSecret }
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
case "callback": {
|
|
529
|
+
if (slug[2]) {
|
|
530
|
+
const provider = slug[2];
|
|
531
|
+
if (method === "GET") {
|
|
532
|
+
return thirdpartyAuthCallbackHandler(
|
|
533
|
+
request,
|
|
534
|
+
{
|
|
535
|
+
provider,
|
|
536
|
+
authService,
|
|
537
|
+
getThirdPartyAuth
|
|
538
|
+
}
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
case "request-password-reset": {
|
|
544
|
+
return requestPasswordResetHandler(request, { passwordRecoveryService });
|
|
545
|
+
}
|
|
546
|
+
case "reset-password": {
|
|
547
|
+
return resetPasswordHandler(request, { passwordRecoveryService });
|
|
367
548
|
}
|
|
368
549
|
}
|
|
369
550
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
551
|
+
case "files": {
|
|
552
|
+
switch (slug[1]) {
|
|
553
|
+
case void 0: {
|
|
554
|
+
switch (method) {
|
|
555
|
+
case "POST": {
|
|
556
|
+
return uploadFileHandler(request, { authService, fileService });
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
default: {
|
|
561
|
+
switch (method) {
|
|
562
|
+
case "DELETE": {
|
|
563
|
+
const fileId = slug[1];
|
|
564
|
+
return deleteFileHandler(
|
|
565
|
+
request,
|
|
566
|
+
{ fileId },
|
|
567
|
+
{ authService, fileRepository: fileService.fileRepository }
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
375
572
|
}
|
|
376
573
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
const fileId = slug[1];
|
|
380
|
-
return fileDeleteHandler(
|
|
381
|
-
request,
|
|
382
|
-
{ fileId },
|
|
383
|
-
{ AUTH, repository: fileRepository }
|
|
384
|
-
);
|
|
385
|
-
}
|
|
574
|
+
default: {
|
|
575
|
+
return NOT_FOUND();
|
|
386
576
|
}
|
|
387
577
|
}
|
|
388
|
-
return new Response("Not Found", { status: 404 });
|
|
389
578
|
};
|
|
390
579
|
return handler;
|
|
391
580
|
};
|
|
392
581
|
// Annotate the CommonJS export names for ESM import in node:
|
|
393
582
|
0 && (module.exports = {
|
|
394
|
-
|
|
583
|
+
createAPIHandler
|
|
395
584
|
});
|