dn-react-router-toolkit 0.2.7 → 0.3.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.
Files changed (276) hide show
  1. package/dist/api/create_handler.d.mts +13 -0
  2. package/dist/api/create_handler.d.ts +13 -0
  3. package/dist/api/create_handler.js +276 -0
  4. package/dist/api/create_handler.mjs +282 -0
  5. package/dist/api/index.d.mts +4 -0
  6. package/dist/api/index.d.ts +4 -0
  7. package/dist/api/index.js +276 -0
  8. package/dist/api/index.mjs +282 -0
  9. package/dist/auth/client/index.d.mts +3 -0
  10. package/dist/auth/client/index.d.ts +3 -0
  11. package/dist/{date.js → auth/client/index.js} +25 -32
  12. package/dist/auth/client/index.mjs +21 -0
  13. package/dist/auth/client/redirect_page.d.mts +1 -0
  14. package/dist/auth/client/redirect_page.d.ts +1 -0
  15. package/dist/auth/index.d.mts +4 -0
  16. package/dist/auth/index.d.ts +4 -0
  17. package/dist/auth/index.js +116 -0
  18. package/dist/auth/index.mjs +89 -0
  19. package/dist/auth/server/index.d.mts +1 -0
  20. package/dist/auth/server/index.d.ts +1 -0
  21. package/dist/{slug.js → auth/server/index.js} +6 -14
  22. package/dist/auth/server/index.mjs +2 -0
  23. package/dist/auth/with_auth.d.mts +2 -6
  24. package/dist/auth/with_auth.d.ts +2 -6
  25. package/dist/auth/with_auth.js +3 -0
  26. package/dist/auth/with_auth.mjs +3 -0
  27. package/dist/{components → client}/client_env.d.mts +1 -1
  28. package/dist/{components → client}/client_env.d.ts +1 -1
  29. package/dist/{components → client}/client_env.js +6 -2
  30. package/dist/{components → client}/client_env.mjs +2 -2
  31. package/dist/client/index.d.mts +3 -0
  32. package/dist/client/index.d.ts +3 -0
  33. package/dist/{auth/client/google_login_button.js → client/index.js} +30 -33
  34. package/dist/client/index.mjs +31 -0
  35. package/dist/client/use_user_agent.d.mts +8 -0
  36. package/dist/client/use_user_agent.d.ts +8 -0
  37. package/dist/{file/client/format_size.js → client/use_user_agent.js} +14 -14
  38. package/dist/client/use_user_agent.mjs +13 -0
  39. package/dist/file/client/index.d.mts +1 -0
  40. package/dist/file/client/index.d.ts +1 -0
  41. package/dist/file/{cdn.js → client/index.js} +6 -16
  42. package/dist/file/client/index.mjs +2 -0
  43. package/dist/file/index.d.mts +1 -0
  44. package/dist/file/index.d.ts +1 -0
  45. package/dist/{cn.js → file/index.js} +6 -14
  46. package/dist/file/index.mjs +2 -0
  47. package/dist/file/server/index.d.mts +1 -0
  48. package/dist/file/server/index.d.ts +1 -0
  49. package/dist/file/server/index.js +24 -0
  50. package/dist/file/server/index.mjs +2 -0
  51. package/dist/http/index.d.mts +1 -1
  52. package/dist/http/index.d.ts +1 -1
  53. package/dist/http/index.js +3 -90
  54. package/dist/http/index.mjs +2 -68
  55. package/dist/index.d.mts +8 -6
  56. package/dist/index.d.ts +8 -6
  57. package/dist/index.js +3 -79
  58. package/dist/index.mjs +2 -58
  59. package/dist/modal/index.d.mts +1 -0
  60. package/dist/modal/index.d.ts +1 -0
  61. package/dist/{sleep.js → modal/index.js} +6 -14
  62. package/dist/modal/index.mjs +2 -0
  63. package/dist/seo/index.d.mts +4 -0
  64. package/dist/seo/index.d.ts +4 -0
  65. package/dist/seo/index.js +304 -0
  66. package/dist/seo/index.mjs +267 -0
  67. package/dist/text_editor/index.d.mts +1 -0
  68. package/dist/text_editor/index.d.ts +1 -0
  69. package/dist/text_editor/index.js +24 -0
  70. package/dist/text_editor/index.mjs +2 -0
  71. package/package.json +58 -32
  72. package/dist/auth/apple_auth.d.mts +0 -38
  73. package/dist/auth/apple_auth.d.ts +0 -38
  74. package/dist/auth/apple_auth.js +0 -88
  75. package/dist/auth/apple_auth.mjs +0 -63
  76. package/dist/auth/auth_repository.d.mts +0 -41
  77. package/dist/auth/auth_repository.d.ts +0 -41
  78. package/dist/auth/auth_repository.js +0 -18
  79. package/dist/auth/auth_repository.mjs +0 -0
  80. package/dist/auth/auth_service.d.mts +0 -63
  81. package/dist/auth/auth_service.d.ts +0 -63
  82. package/dist/auth/auth_service.js +0 -210
  83. package/dist/auth/auth_service.mjs +0 -171
  84. package/dist/auth/client/google_login_button.d.mts +0 -7
  85. package/dist/auth/client/google_login_button.d.ts +0 -7
  86. package/dist/auth/client/google_login_button.mjs +0 -37
  87. package/dist/auth/client/provider.d.mts +0 -24
  88. package/dist/auth/client/provider.d.ts +0 -24
  89. package/dist/auth/client/provider.js +0 -154
  90. package/dist/auth/client/provider.mjs +0 -118
  91. package/dist/auth/google_auth.d.mts +0 -33
  92. package/dist/auth/google_auth.d.ts +0 -33
  93. package/dist/auth/google_auth.js +0 -135
  94. package/dist/auth/google_auth.mjs +0 -108
  95. package/dist/auth/handlers/find_auth.d.mts +0 -13
  96. package/dist/auth/handlers/find_auth.d.ts +0 -13
  97. package/dist/auth/handlers/find_auth.js +0 -82
  98. package/dist/auth/handlers/find_auth.mjs +0 -55
  99. package/dist/auth/handlers/login.d.mts +0 -13
  100. package/dist/auth/handlers/login.d.ts +0 -13
  101. package/dist/auth/handlers/login.js +0 -107
  102. package/dist/auth/handlers/login.mjs +0 -80
  103. package/dist/auth/handlers/login_with_thirdparty.d.mts +0 -15
  104. package/dist/auth/handlers/login_with_thirdparty.d.ts +0 -15
  105. package/dist/auth/handlers/login_with_thirdparty.js +0 -98
  106. package/dist/auth/handlers/login_with_thirdparty.mjs +0 -71
  107. package/dist/auth/handlers/logout.d.mts +0 -13
  108. package/dist/auth/handlers/logout.d.ts +0 -13
  109. package/dist/auth/handlers/logout.js +0 -102
  110. package/dist/auth/handlers/logout.mjs +0 -75
  111. package/dist/auth/handlers/refresh.d.mts +0 -13
  112. package/dist/auth/handlers/refresh.d.ts +0 -13
  113. package/dist/auth/handlers/refresh.js +0 -92
  114. package/dist/auth/handlers/refresh.mjs +0 -65
  115. package/dist/auth/handlers/request_password_reset.d.mts +0 -10
  116. package/dist/auth/handlers/request_password_reset.d.ts +0 -10
  117. package/dist/auth/handlers/request_password_reset.js +0 -87
  118. package/dist/auth/handlers/request_password_reset.mjs +0 -60
  119. package/dist/auth/handlers/reset_password.d.mts +0 -10
  120. package/dist/auth/handlers/reset_password.d.ts +0 -10
  121. package/dist/auth/handlers/reset_password.js +0 -88
  122. package/dist/auth/handlers/reset_password.mjs +0 -61
  123. package/dist/auth/handlers/signup.d.mts +0 -15
  124. package/dist/auth/handlers/signup.d.ts +0 -15
  125. package/dist/auth/handlers/signup.js +0 -147
  126. package/dist/auth/handlers/signup.mjs +0 -112
  127. package/dist/auth/handlers/signup_with_thirdparty.d.mts +0 -17
  128. package/dist/auth/handlers/signup_with_thirdparty.d.ts +0 -17
  129. package/dist/auth/handlers/signup_with_thirdparty.js +0 -123
  130. package/dist/auth/handlers/signup_with_thirdparty.mjs +0 -98
  131. package/dist/auth/handlers/thirdparty_auth_callback.d.mts +0 -16
  132. package/dist/auth/handlers/thirdparty_auth_callback.d.ts +0 -16
  133. package/dist/auth/handlers/thirdparty_auth_callback.js +0 -129
  134. package/dist/auth/handlers/thirdparty_auth_callback.mjs +0 -102
  135. package/dist/auth/jwt_manager.d.mts +0 -38
  136. package/dist/auth/jwt_manager.d.ts +0 -38
  137. package/dist/auth/jwt_manager.js +0 -90
  138. package/dist/auth/jwt_manager.mjs +0 -65
  139. package/dist/auth/kakao_auth.d.mts +0 -27
  140. package/dist/auth/kakao_auth.d.ts +0 -27
  141. package/dist/auth/kakao_auth.js +0 -56
  142. package/dist/auth/kakao_auth.mjs +0 -31
  143. package/dist/auth/password_recovery.d.mts +0 -34
  144. package/dist/auth/password_recovery.d.ts +0 -34
  145. package/dist/auth/password_recovery.js +0 -169
  146. package/dist/auth/password_recovery.mjs +0 -134
  147. package/dist/auth/thirdparty_auth.d.mts +0 -41
  148. package/dist/auth/thirdparty_auth.d.ts +0 -41
  149. package/dist/auth/thirdparty_auth.js +0 -113
  150. package/dist/auth/thirdparty_auth.mjs +0 -86
  151. package/dist/cn.d.mts +0 -3
  152. package/dist/cn.d.ts +0 -3
  153. package/dist/cn.mjs +0 -7
  154. package/dist/components/index.d.mts +0 -5
  155. package/dist/components/index.d.ts +0 -5
  156. package/dist/components/index.js +0 -261
  157. package/dist/components/index.mjs +0 -219
  158. package/dist/components/modal/fullscreen_container.d.mts +0 -7
  159. package/dist/components/modal/fullscreen_container.d.ts +0 -7
  160. package/dist/components/modal/fullscreen_container.js +0 -102
  161. package/dist/components/modal/fullscreen_container.mjs +0 -68
  162. package/dist/components/modal/hooks.d.mts +0 -18
  163. package/dist/components/modal/hooks.d.ts +0 -18
  164. package/dist/components/modal/hooks.js +0 -236
  165. package/dist/components/modal/hooks.mjs +0 -204
  166. package/dist/components/modal/index.d.mts +0 -4
  167. package/dist/components/modal/index.d.ts +0 -4
  168. package/dist/components/modal/index.js +0 -238
  169. package/dist/components/modal/index.mjs +0 -203
  170. package/dist/components/modal/modal.d.mts +0 -13
  171. package/dist/components/modal/modal.d.ts +0 -13
  172. package/dist/components/modal/modal.js +0 -155
  173. package/dist/components/modal/modal.mjs +0 -130
  174. package/dist/components/styles.d.mts +0 -9
  175. package/dist/components/styles.d.ts +0 -9
  176. package/dist/components/styles.js +0 -48
  177. package/dist/components/styles.mjs +0 -17
  178. package/dist/date.d.mts +0 -5
  179. package/dist/date.d.ts +0 -5
  180. package/dist/date.mjs +0 -29
  181. package/dist/file/cdn.d.mts +0 -6
  182. package/dist/file/cdn.d.ts +0 -6
  183. package/dist/file/cdn.mjs +0 -9
  184. package/dist/file/client/drop_file_input.d.mts +0 -36
  185. package/dist/file/client/drop_file_input.d.ts +0 -36
  186. package/dist/file/client/drop_file_input.js +0 -323
  187. package/dist/file/client/drop_file_input.mjs +0 -294
  188. package/dist/file/client/file_upload_button.d.mts +0 -10
  189. package/dist/file/client/file_upload_button.d.ts +0 -10
  190. package/dist/file/client/file_upload_button.js +0 -89
  191. package/dist/file/client/file_upload_button.mjs +0 -58
  192. package/dist/file/client/file_uploader.d.mts +0 -13
  193. package/dist/file/client/file_uploader.d.ts +0 -13
  194. package/dist/file/client/file_uploader.js +0 -163
  195. package/dist/file/client/file_uploader.mjs +0 -136
  196. package/dist/file/client/format_size.d.mts +0 -3
  197. package/dist/file/client/format_size.d.ts +0 -3
  198. package/dist/file/client/format_size.mjs +0 -13
  199. package/dist/file/client/metadata.d.mts +0 -7
  200. package/dist/file/client/metadata.d.ts +0 -7
  201. package/dist/file/client/metadata.js +0 -85
  202. package/dist/file/client/metadata.mjs +0 -60
  203. package/dist/file/file_repository.d.mts +0 -16
  204. package/dist/file/file_repository.d.ts +0 -16
  205. package/dist/file/file_repository.js +0 -18
  206. package/dist/file/file_repository.mjs +0 -0
  207. package/dist/file/file_service.d.mts +0 -32
  208. package/dist/file/file_service.d.ts +0 -32
  209. package/dist/file/file_service.js +0 -66
  210. package/dist/file/file_service.mjs +0 -41
  211. package/dist/file/handlers/delete_file.d.mts +0 -17
  212. package/dist/file/handlers/delete_file.d.ts +0 -17
  213. package/dist/file/handlers/delete_file.js +0 -99
  214. package/dist/file/handlers/delete_file.mjs +0 -72
  215. package/dist/file/handlers/upload_file.d.mts +0 -16
  216. package/dist/file/handlers/upload_file.d.ts +0 -16
  217. package/dist/file/handlers/upload_file.js +0 -106
  218. package/dist/file/handlers/upload_file.mjs +0 -79
  219. package/dist/file/object_storage.d.mts +0 -20
  220. package/dist/file/object_storage.d.ts +0 -20
  221. package/dist/file/object_storage.js +0 -90
  222. package/dist/file/object_storage.mjs +0 -70
  223. package/dist/file/responsive_image.d.mts +0 -20
  224. package/dist/file/responsive_image.d.ts +0 -20
  225. package/dist/file/responsive_image.js +0 -132
  226. package/dist/file/responsive_image.mjs +0 -96
  227. package/dist/http/response.d.mts +0 -19
  228. package/dist/http/response.d.ts +0 -19
  229. package/dist/http/response.js +0 -109
  230. package/dist/http/response.mjs +0 -68
  231. package/dist/route/api.d.mts +0 -21
  232. package/dist/route/api.d.ts +0 -21
  233. package/dist/route/api.js +0 -584
  234. package/dist/route/api.mjs +0 -547
  235. package/dist/singleton.d.mts +0 -3
  236. package/dist/singleton.d.ts +0 -3
  237. package/dist/singleton.js +0 -37
  238. package/dist/singleton.mjs +0 -12
  239. package/dist/sleep.d.mts +0 -3
  240. package/dist/sleep.d.ts +0 -3
  241. package/dist/sleep.mjs +0 -7
  242. package/dist/slug.d.mts +0 -3
  243. package/dist/slug.d.ts +0 -3
  244. package/dist/slug.mjs +0 -7
  245. package/dist/text_editor/attach_media.d.mts +0 -16
  246. package/dist/text_editor/attach_media.d.ts +0 -16
  247. package/dist/text_editor/attach_media.js +0 -237
  248. package/dist/text_editor/attach_media.mjs +0 -210
  249. package/dist/text_editor/plugins/drag_and_drop.d.mts +0 -13
  250. package/dist/text_editor/plugins/drag_and_drop.d.ts +0 -13
  251. package/dist/text_editor/plugins/drag_and_drop.js +0 -59
  252. package/dist/text_editor/plugins/drag_and_drop.mjs +0 -34
  253. package/dist/text_editor/plugins/keymap.d.mts +0 -5
  254. package/dist/text_editor/plugins/keymap.d.ts +0 -5
  255. package/dist/text_editor/plugins/keymap.js +0 -40
  256. package/dist/text_editor/plugins/keymap.mjs +0 -15
  257. package/dist/text_editor/plugins/placehoder.d.mts +0 -5
  258. package/dist/text_editor/plugins/placehoder.d.ts +0 -5
  259. package/dist/text_editor/plugins/placehoder.js +0 -112
  260. package/dist/text_editor/plugins/placehoder.mjs +0 -87
  261. package/dist/text_editor/plugins/trailing_paragraph.d.mts +0 -5
  262. package/dist/text_editor/plugins/trailing_paragraph.d.ts +0 -5
  263. package/dist/text_editor/plugins/trailing_paragraph.js +0 -46
  264. package/dist/text_editor/plugins/trailing_paragraph.mjs +0 -21
  265. package/dist/text_editor/plugins/upload_placeholder.d.mts +0 -7
  266. package/dist/text_editor/plugins/upload_placeholder.d.ts +0 -7
  267. package/dist/text_editor/plugins/upload_placeholder.js +0 -94
  268. package/dist/text_editor/plugins/upload_placeholder.mjs +0 -68
  269. package/dist/text_editor/schema.d.mts +0 -9
  270. package/dist/text_editor/schema.d.ts +0 -9
  271. package/dist/text_editor/schema.js +0 -354
  272. package/dist/text_editor/schema.mjs +0 -319
  273. package/dist/text_editor/text_editor.d.mts +0 -45
  274. package/dist/text_editor/text_editor.d.ts +0 -45
  275. package/dist/text_editor/text_editor.js +0 -834
  276. package/dist/text_editor/text_editor.mjs +0 -806
@@ -1,210 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
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
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/auth/auth_service.ts
31
- var auth_service_exports = {};
32
- __export(auth_service_exports, {
33
- ACCESS_TOKEN_COOKIE: () => ACCESS_TOKEN_COOKIE,
34
- ACCESS_TOKEN_KEY: () => ACCESS_TOKEN_KEY,
35
- AuthService: () => AuthService,
36
- REFRESH_TOKEN_COOKIE: () => REFRESH_TOKEN_COOKIE,
37
- REFRESH_TOKEN_KEY: () => REFRESH_TOKEN_KEY
38
- });
39
- module.exports = __toCommonJS(auth_service_exports);
40
- var import_bcryptjs = __toESM(require("bcryptjs"));
41
- var import_react_router = require("react-router");
42
- var ACCESS_TOKEN_KEY = "access_token";
43
- var REFRESH_TOKEN_KEY = "refresh_token";
44
- var ACCESS_TOKEN_COOKIE = (0, import_react_router.createCookie)(ACCESS_TOKEN_KEY, {
45
- path: "/",
46
- httpOnly: process.env.NODE_ENV === "production",
47
- secure: process.env.NODE_ENV === "production",
48
- sameSite: "strict"
49
- });
50
- var REFRESH_TOKEN_COOKIE = (0, import_react_router.createCookie)(REFRESH_TOKEN_KEY, {
51
- path: "/",
52
- httpOnly: process.env.NODE_ENV === "production",
53
- secure: process.env.NODE_ENV === "production",
54
- sameSite: "strict"
55
- });
56
- var AuthService = class {
57
- authRepository;
58
- jwtManager;
59
- objectStorage;
60
- constructor({
61
- authRepository,
62
- jwtManager,
63
- objectStorage
64
- }) {
65
- this.authRepository = authRepository;
66
- this.jwtManager = jwtManager;
67
- this.objectStorage = objectStorage;
68
- }
69
- async verify(request) {
70
- const accessToken = await this.getAccessTokenFromRequest(request);
71
- if (accessToken) {
72
- return this.jwtManager.verifyAccessToken(accessToken);
73
- }
74
- }
75
- async verifyOrRefresh(request) {
76
- const payload = await this.verify(request);
77
- if (payload) {
78
- return payload;
79
- }
80
- return this.refresh(request);
81
- }
82
- async getAccessTokenFromRequest(request) {
83
- if (request.headers.get("Authorization")) {
84
- return request.headers.get("Authorization")?.replace("Bearer ", "");
85
- }
86
- return this.getAccessTokenFromCookies(request);
87
- }
88
- async getAccessTokenFromCookies(request) {
89
- const accessToken = await ACCESS_TOKEN_COOKIE.parse(
90
- request.headers.get("cookie")
91
- );
92
- return accessToken;
93
- }
94
- async getRefreshTokenFromCookies(request) {
95
- const refreshToken = await REFRESH_TOKEN_COOKIE.parse(
96
- request.headers.get("cookie")
97
- );
98
- return refreshToken;
99
- }
100
- async refresh(request) {
101
- const refreshToken = await this.getRefreshTokenFromCookies(request);
102
- if (refreshToken) {
103
- try {
104
- const refreshedAccessToken = await this.refreshAccessToken(
105
- refreshToken
106
- );
107
- await this.getAccessTokenSetCookie(refreshedAccessToken);
108
- const payload = this.jwtManager.decode(refreshedAccessToken);
109
- if (payload) {
110
- return payload;
111
- }
112
- } catch (e) {
113
- if (e instanceof Error) {
114
- console.log(e.message);
115
- }
116
- return;
117
- }
118
- }
119
- }
120
- async login({ id, password }) {
121
- const credential = await this.authRepository.findCredentialById(id);
122
- if (!credential) {
123
- throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
124
- }
125
- if (!await import_bcryptjs.default.compare(password, credential.password)) {
126
- throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
127
- }
128
- const user = await this.authRepository.findUserById(credential.userId);
129
- if (!user) {
130
- throw Error("\uD68C\uC6D0 \uC815\uBCF4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
131
- }
132
- const { accessToken, refreshToken } = await this.issueTokenPair(user);
133
- return {
134
- accessToken,
135
- refreshToken
136
- };
137
- }
138
- async issueAccessToken(user) {
139
- return this.jwtManager.signAccessToken({
140
- userId: user.id,
141
- role: user.role,
142
- name: user.name
143
- });
144
- }
145
- async issueTokenPair(user) {
146
- const refreshToken = await this.jwtManager.signRefreshToken({
147
- userId: user.id,
148
- role: user.role,
149
- name: user.name
150
- });
151
- await this.authRepository.updateUserRefreshToken(
152
- user.id,
153
- await import_bcryptjs.default.hash(refreshToken, 10)
154
- );
155
- const accessToken = await this.issueAccessToken(user);
156
- return { refreshToken, accessToken };
157
- }
158
- async refreshAccessToken(refreshToken) {
159
- const payload = await this.jwtManager.verifyRefreshToken(refreshToken);
160
- if (!payload) {
161
- throw new Error("\uD1A0\uD070\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
162
- }
163
- const { userId } = payload;
164
- if (typeof userId !== "string") {
165
- throw new Error("\uD1A0\uD070\uC774 \uC704\uC870\uB418\uC5C8\uC2B5\uB2C8\uB2E4.");
166
- }
167
- const user = await this.authRepository.findUserById(userId);
168
- if (!user) {
169
- throw Error("\uC774\uC6A9\uC790\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.");
170
- }
171
- if (!user.refreshToken) {
172
- throw Error("\uC778\uC99D \uC815\uBCF4\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.");
173
- }
174
- if (await import_bcryptjs.default.compare(user.refreshToken, refreshToken)) {
175
- throw Error("\uD1A0\uD070\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
176
- }
177
- const accessToken = await this.issueAccessToken(user);
178
- return accessToken;
179
- }
180
- async getAccessTokenSetCookie(accessToken) {
181
- return ACCESS_TOKEN_COOKIE.serialize(accessToken, {
182
- expires: accessToken ? this.jwtManager.getExpirationTime(accessToken) : /* @__PURE__ */ new Date(0)
183
- });
184
- }
185
- async getRefreshTokenSetCookie(refreshToken) {
186
- return REFRESH_TOKEN_COOKIE.serialize(refreshToken, {
187
- expires: refreshToken ? this.jwtManager.getExpirationTime(refreshToken) : /* @__PURE__ */ new Date(0)
188
- });
189
- }
190
- async findUser(provider, info) {
191
- const thirdPartyAuth = await this.authRepository.findThirdPartyAuth(
192
- provider,
193
- info.id
194
- );
195
- if (thirdPartyAuth) {
196
- const user = await this.authRepository.findUserById(thirdPartyAuth.userId);
197
- if (user) {
198
- return user;
199
- }
200
- }
201
- }
202
- };
203
- // Annotate the CommonJS export names for ESM import in node:
204
- 0 && (module.exports = {
205
- ACCESS_TOKEN_COOKIE,
206
- ACCESS_TOKEN_KEY,
207
- AuthService,
208
- REFRESH_TOKEN_COOKIE,
209
- REFRESH_TOKEN_KEY
210
- });
@@ -1,171 +0,0 @@
1
- // src/auth/auth_service.ts
2
- import bcryptjs from "bcryptjs";
3
- import { createCookie } from "react-router";
4
- var ACCESS_TOKEN_KEY = "access_token";
5
- var REFRESH_TOKEN_KEY = "refresh_token";
6
- var ACCESS_TOKEN_COOKIE = createCookie(ACCESS_TOKEN_KEY, {
7
- path: "/",
8
- httpOnly: process.env.NODE_ENV === "production",
9
- secure: process.env.NODE_ENV === "production",
10
- sameSite: "strict"
11
- });
12
- var REFRESH_TOKEN_COOKIE = createCookie(REFRESH_TOKEN_KEY, {
13
- path: "/",
14
- httpOnly: process.env.NODE_ENV === "production",
15
- secure: process.env.NODE_ENV === "production",
16
- sameSite: "strict"
17
- });
18
- var AuthService = class {
19
- authRepository;
20
- jwtManager;
21
- objectStorage;
22
- constructor({
23
- authRepository,
24
- jwtManager,
25
- objectStorage
26
- }) {
27
- this.authRepository = authRepository;
28
- this.jwtManager = jwtManager;
29
- this.objectStorage = objectStorage;
30
- }
31
- async verify(request) {
32
- const accessToken = await this.getAccessTokenFromRequest(request);
33
- if (accessToken) {
34
- return this.jwtManager.verifyAccessToken(accessToken);
35
- }
36
- }
37
- async verifyOrRefresh(request) {
38
- const payload = await this.verify(request);
39
- if (payload) {
40
- return payload;
41
- }
42
- return this.refresh(request);
43
- }
44
- async getAccessTokenFromRequest(request) {
45
- if (request.headers.get("Authorization")) {
46
- return request.headers.get("Authorization")?.replace("Bearer ", "");
47
- }
48
- return this.getAccessTokenFromCookies(request);
49
- }
50
- async getAccessTokenFromCookies(request) {
51
- const accessToken = await ACCESS_TOKEN_COOKIE.parse(
52
- request.headers.get("cookie")
53
- );
54
- return accessToken;
55
- }
56
- async getRefreshTokenFromCookies(request) {
57
- const refreshToken = await REFRESH_TOKEN_COOKIE.parse(
58
- request.headers.get("cookie")
59
- );
60
- return refreshToken;
61
- }
62
- async refresh(request) {
63
- const refreshToken = await this.getRefreshTokenFromCookies(request);
64
- if (refreshToken) {
65
- try {
66
- const refreshedAccessToken = await this.refreshAccessToken(
67
- refreshToken
68
- );
69
- await this.getAccessTokenSetCookie(refreshedAccessToken);
70
- const payload = this.jwtManager.decode(refreshedAccessToken);
71
- if (payload) {
72
- return payload;
73
- }
74
- } catch (e) {
75
- if (e instanceof Error) {
76
- console.log(e.message);
77
- }
78
- return;
79
- }
80
- }
81
- }
82
- async login({ id, password }) {
83
- const credential = await this.authRepository.findCredentialById(id);
84
- if (!credential) {
85
- throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
86
- }
87
- if (!await bcryptjs.compare(password, credential.password)) {
88
- throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
89
- }
90
- const user = await this.authRepository.findUserById(credential.userId);
91
- if (!user) {
92
- throw Error("\uD68C\uC6D0 \uC815\uBCF4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
93
- }
94
- const { accessToken, refreshToken } = await this.issueTokenPair(user);
95
- return {
96
- accessToken,
97
- refreshToken
98
- };
99
- }
100
- async issueAccessToken(user) {
101
- return this.jwtManager.signAccessToken({
102
- userId: user.id,
103
- role: user.role,
104
- name: user.name
105
- });
106
- }
107
- async issueTokenPair(user) {
108
- const refreshToken = await this.jwtManager.signRefreshToken({
109
- userId: user.id,
110
- role: user.role,
111
- name: user.name
112
- });
113
- await this.authRepository.updateUserRefreshToken(
114
- user.id,
115
- await bcryptjs.hash(refreshToken, 10)
116
- );
117
- const accessToken = await this.issueAccessToken(user);
118
- return { refreshToken, accessToken };
119
- }
120
- async refreshAccessToken(refreshToken) {
121
- const payload = await this.jwtManager.verifyRefreshToken(refreshToken);
122
- if (!payload) {
123
- throw new Error("\uD1A0\uD070\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
124
- }
125
- const { userId } = payload;
126
- if (typeof userId !== "string") {
127
- throw new Error("\uD1A0\uD070\uC774 \uC704\uC870\uB418\uC5C8\uC2B5\uB2C8\uB2E4.");
128
- }
129
- const user = await this.authRepository.findUserById(userId);
130
- if (!user) {
131
- throw Error("\uC774\uC6A9\uC790\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.");
132
- }
133
- if (!user.refreshToken) {
134
- throw Error("\uC778\uC99D \uC815\uBCF4\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.");
135
- }
136
- if (await bcryptjs.compare(user.refreshToken, refreshToken)) {
137
- throw Error("\uD1A0\uD070\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
138
- }
139
- const accessToken = await this.issueAccessToken(user);
140
- return accessToken;
141
- }
142
- async getAccessTokenSetCookie(accessToken) {
143
- return ACCESS_TOKEN_COOKIE.serialize(accessToken, {
144
- expires: accessToken ? this.jwtManager.getExpirationTime(accessToken) : /* @__PURE__ */ new Date(0)
145
- });
146
- }
147
- async getRefreshTokenSetCookie(refreshToken) {
148
- return REFRESH_TOKEN_COOKIE.serialize(refreshToken, {
149
- expires: refreshToken ? this.jwtManager.getExpirationTime(refreshToken) : /* @__PURE__ */ new Date(0)
150
- });
151
- }
152
- async findUser(provider, info) {
153
- const thirdPartyAuth = await this.authRepository.findThirdPartyAuth(
154
- provider,
155
- info.id
156
- );
157
- if (thirdPartyAuth) {
158
- const user = await this.authRepository.findUserById(thirdPartyAuth.userId);
159
- if (user) {
160
- return user;
161
- }
162
- }
163
- }
164
- };
165
- export {
166
- ACCESS_TOKEN_COOKIE,
167
- ACCESS_TOKEN_KEY,
168
- AuthService,
169
- REFRESH_TOKEN_COOKIE,
170
- REFRESH_TOKEN_KEY
171
- };
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
-
3
- declare function GoogleLoginButton({ className, }: {
4
- className?: string;
5
- }): React.JSX.Element;
6
-
7
- export { GoogleLoginButton };
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
-
3
- declare function GoogleLoginButton({ className, }: {
4
- className?: string;
5
- }): React.JSX.Element;
6
-
7
- export { GoogleLoginButton };
@@ -1,37 +0,0 @@
1
- // src/auth/client/google_login_button.tsx
2
- import React2 from "react";
3
- import { FcGoogle } from "react-icons/fc";
4
- import { useSearchParams } from "react-router";
5
-
6
- // src/auth/client/provider.tsx
7
- import React from "react";
8
- import { createContext, useContext } from "react";
9
- import { useNavigate, useRouteLoaderData } from "react-router";
10
- var AuthContext = createContext({});
11
- var useAuth = () => {
12
- return useContext(AuthContext);
13
- };
14
-
15
- // src/auth/client/google_login_button.tsx
16
- function GoogleLoginButton({
17
- className = "max-w-[300px] w-full"
18
- }) {
19
- const { loginWithGoogle } = useAuth();
20
- const [searchParams] = useSearchParams();
21
- const redirectUrl = searchParams.get("redirectUrl") || "";
22
- return /* @__PURE__ */ React2.createElement("div", { className }, /* @__PURE__ */ React2.createElement(
23
- "button",
24
- {
25
- type: "button",
26
- onClick: () => {
27
- loginWithGoogle(redirectUrl);
28
- },
29
- className: "relative flex items-center border border-neutral-300 px-4 py-3 no-underline hover:no-underline bg-white hover:bg-neutral-100 rounded"
30
- },
31
- /* @__PURE__ */ React2.createElement(FcGoogle, null),
32
- /* @__PURE__ */ React2.createElement("p", { className: "text-[14px] text-black absolute left-0 right-0 text-center" }, "\uAD6C\uAE00\uB85C \uACC4\uC18D\uD558\uAE30")
33
- ));
34
- }
35
- export {
36
- GoogleLoginButton
37
- };
@@ -1,24 +0,0 @@
1
- import React from 'react';
2
- import { AccessTokenPayload } from '../jwt_manager.mjs';
3
- import 'jose';
4
-
5
- type AuthContextValue = {
6
- auth: AccessTokenPayload | undefined;
7
- login: (id: string, password: string) => Promise<AccessTokenPayload>;
8
- loginWithGoogle: (redirectUrl?: string) => Promise<void>;
9
- logout: () => Promise<void>;
10
- signup: (email: string, password: string, passwordConfirm: string) => Promise<AccessTokenPayload>;
11
- requestResetPassword: (email: string) => Promise<boolean>;
12
- resetPassword: (token: string, password: string, passwordConfirm: string) => Promise<boolean>;
13
- };
14
- declare const AuthContext: React.Context<AuthContextValue>;
15
- declare const useAuth: () => AuthContextValue;
16
- declare function AuthProvider({ children, googleAuth, }: {
17
- children: React.ReactNode;
18
- googleAuth?: {
19
- googleClientId: string;
20
- googleRedirectUrl: string;
21
- };
22
- }): React.JSX.Element;
23
-
24
- export { AuthContext, type AuthContextValue, AuthProvider as default, useAuth };
@@ -1,24 +0,0 @@
1
- import React from 'react';
2
- import { AccessTokenPayload } from '../jwt_manager.js';
3
- import 'jose';
4
-
5
- type AuthContextValue = {
6
- auth: AccessTokenPayload | undefined;
7
- login: (id: string, password: string) => Promise<AccessTokenPayload>;
8
- loginWithGoogle: (redirectUrl?: string) => Promise<void>;
9
- logout: () => Promise<void>;
10
- signup: (email: string, password: string, passwordConfirm: string) => Promise<AccessTokenPayload>;
11
- requestResetPassword: (email: string) => Promise<boolean>;
12
- resetPassword: (token: string, password: string, passwordConfirm: string) => Promise<boolean>;
13
- };
14
- declare const AuthContext: React.Context<AuthContextValue>;
15
- declare const useAuth: () => AuthContextValue;
16
- declare function AuthProvider({ children, googleAuth, }: {
17
- children: React.ReactNode;
18
- googleAuth?: {
19
- googleClientId: string;
20
- googleRedirectUrl: string;
21
- };
22
- }): React.JSX.Element;
23
-
24
- export { AuthContext, type AuthContextValue, AuthProvider as default, useAuth };
@@ -1,154 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
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
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/auth/client/provider.tsx
31
- var provider_exports = {};
32
- __export(provider_exports, {
33
- AuthContext: () => AuthContext,
34
- default: () => AuthProvider,
35
- useAuth: () => useAuth
36
- });
37
- module.exports = __toCommonJS(provider_exports);
38
- var import_react = __toESM(require("react"));
39
- var import_react2 = require("react");
40
- var import_react_router = require("react-router");
41
- var AuthContext = (0, import_react2.createContext)({});
42
- var useAuth = () => {
43
- return (0, import_react2.useContext)(AuthContext);
44
- };
45
- function AuthProvider({
46
- children,
47
- googleAuth
48
- }) {
49
- const data = (0, import_react_router.useRouteLoaderData)("root");
50
- const auth = data?.AUTH;
51
- const navigate = (0, import_react_router.useNavigate)();
52
- const login = async (id, password) => {
53
- const res = await fetch("/api/auth/login", {
54
- method: "POST",
55
- headers: {
56
- "Content-Type": "application/json"
57
- },
58
- body: JSON.stringify({ id, password })
59
- });
60
- if (!res.ok) {
61
- const { message } = await res.json();
62
- throw new Error(message);
63
- }
64
- return res.json();
65
- };
66
- const loginWithGoogle = async (redirectUrl = "/") => {
67
- if (!googleAuth) {
68
- alert("\uAD6C\uAE00 \uB85C\uADF8\uC778 \uC124\uC815\uC774 \uB418\uC5B4\uC788\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
69
- return;
70
- }
71
- const { googleClientId, googleRedirectUrl } = googleAuth;
72
- const href = new URL("https://accounts.google.com/o/oauth2/v2/auth");
73
- href.searchParams.append("client_id", googleClientId);
74
- href.searchParams.append("redirect_uri", googleRedirectUrl);
75
- href.searchParams.append("response_type", "code");
76
- href.searchParams.append("scope", "email profile");
77
- href.searchParams.append("state", redirectUrl);
78
- window.location.href = href.toString();
79
- };
80
- const logout = async () => {
81
- const ok = confirm("\uC815\uB9D0 \uB85C\uADF8\uC544\uC6C3 \uD558\uC2DC\uACA0\uC2B5\uB2C8\uAE4C?");
82
- if (!ok) {
83
- return;
84
- }
85
- const res = await fetch("/api/auth/logout", {
86
- method: "POST"
87
- });
88
- if (res.ok) {
89
- navigate("/");
90
- } else {
91
- const { message } = await res.json();
92
- alert(message);
93
- }
94
- };
95
- const signup = async (email, password, passwordConfirm) => {
96
- const response = await fetch("/api/auth/signup", {
97
- method: "POST",
98
- headers: {
99
- "Content-Type": "application/json"
100
- },
101
- body: JSON.stringify({ email, password, passwordConfirm })
102
- });
103
- if (!response.ok) {
104
- const { message } = await response.json();
105
- throw new Error(message);
106
- }
107
- return response.json();
108
- };
109
- const requestResetPassword = async (email) => {
110
- const response = await fetch("/api/auth/request-password-reset", {
111
- method: "POST",
112
- headers: {
113
- "Content-Type": "application/json"
114
- },
115
- body: JSON.stringify({ email })
116
- });
117
- if (!response.ok) {
118
- const { message } = await response.json();
119
- alert(message);
120
- return false;
121
- }
122
- return true;
123
- };
124
- const resetPassword = async (token, password, passwordConfirm) => {
125
- const response = await fetch("/api/auth/reset-password", {
126
- method: "POST",
127
- headers: {
128
- "Content-Type": "application/json"
129
- },
130
- body: JSON.stringify({ token, password, passwordConfirm })
131
- });
132
- if (!response.ok) {
133
- const { message } = await response.json();
134
- alert(message);
135
- return false;
136
- }
137
- return true;
138
- };
139
- const authContextValue = {
140
- auth,
141
- login,
142
- logout,
143
- loginWithGoogle,
144
- signup,
145
- requestResetPassword,
146
- resetPassword
147
- };
148
- return /* @__PURE__ */ import_react.default.createElement(AuthContext.Provider, { value: authContextValue }, children);
149
- }
150
- // Annotate the CommonJS export names for ESM import in node:
151
- 0 && (module.exports = {
152
- AuthContext,
153
- useAuth
154
- });