dn-react-router-toolkit 0.1.12 → 0.2.0

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 (183) hide show
  1. package/dist/auth/apple_auth.d.mts +38 -0
  2. package/dist/auth/apple_auth.d.ts +38 -0
  3. package/dist/{auth-kit → auth}/apple_auth.js +31 -18
  4. package/dist/auth/apple_auth.mjs +63 -0
  5. package/dist/{auth-kit/repository.d.mts → auth/auth_repository.d.mts} +6 -9
  6. package/dist/{auth-kit/repository.d.ts → auth/auth_repository.d.ts} +6 -9
  7. package/dist/{file-kit/repository.js → auth/auth_repository.js} +3 -3
  8. package/dist/{auth-kit → auth}/auth_service.d.mts +11 -22
  9. package/dist/{auth-kit → auth}/auth_service.d.ts +11 -22
  10. package/dist/{auth-kit → auth}/auth_service.js +23 -76
  11. package/dist/{auth-kit → auth}/auth_service.mjs +23 -76
  12. package/dist/auth/client/google_login_button.d.mts +7 -0
  13. package/dist/auth/client/google_login_button.d.ts +7 -0
  14. package/dist/{auth-kit → auth}/client/google_login_button.js +24 -19
  15. package/dist/auth/client/google_login_button.mjs +37 -0
  16. package/dist/auth/client/provider.d.mts +23 -0
  17. package/dist/auth/client/provider.d.ts +23 -0
  18. package/dist/auth/client/provider.js +137 -0
  19. package/dist/auth/client/provider.mjs +101 -0
  20. package/dist/{auth-kit → auth}/client/redirect_page.js +1 -1
  21. package/dist/{auth-kit → auth}/client/redirect_page.mjs +1 -1
  22. package/dist/auth/google_auth.d.mts +33 -0
  23. package/dist/auth/google_auth.d.ts +33 -0
  24. package/dist/{auth-kit → auth}/google_auth.js +23 -32
  25. package/dist/{auth-kit → auth}/google_auth.mjs +22 -31
  26. package/dist/auth/handlers/find_auth.d.mts +13 -0
  27. package/dist/auth/handlers/find_auth.d.ts +13 -0
  28. package/dist/{route/api/auth/route.js → auth/handlers/find_auth.js} +10 -10
  29. package/dist/{route/api/auth/route.mjs → auth/handlers/find_auth.mjs} +5 -5
  30. package/dist/auth/handlers/login.d.mts +13 -0
  31. package/dist/auth/handlers/login.d.ts +13 -0
  32. package/dist/{route/api/auth/login/route.js → auth/handlers/login.js} +17 -17
  33. package/dist/{route/api/auth/login/route.mjs → auth/handlers/login.mjs} +12 -12
  34. package/dist/auth/handlers/login_with_thirdparty.d.mts +15 -0
  35. package/dist/auth/handlers/login_with_thirdparty.d.ts +15 -0
  36. package/dist/{route/api/auth/login/[provider]/route.js → auth/handlers/login_with_thirdparty.js} +12 -27
  37. package/dist/{route/api/auth/login/[provider]/route.mjs → auth/handlers/login_with_thirdparty.mjs} +7 -22
  38. package/dist/auth/handlers/logout.d.mts +13 -0
  39. package/dist/auth/handlers/logout.d.ts +13 -0
  40. package/dist/{route/api/auth/logout/route.js → auth/handlers/logout.js} +15 -11
  41. package/dist/{route/api/auth/logout/route.mjs → auth/handlers/logout.mjs} +11 -7
  42. package/dist/auth/handlers/refresh.d.mts +13 -0
  43. package/dist/auth/handlers/refresh.d.ts +13 -0
  44. package/dist/{route/api/auth/refresh/route.js → auth/handlers/refresh.js} +12 -12
  45. package/dist/{route/api/auth/refresh/route.mjs → auth/handlers/refresh.mjs} +7 -7
  46. package/dist/auth/handlers/signup.d.mts +15 -0
  47. package/dist/auth/handlers/signup.d.ts +15 -0
  48. package/dist/auth/handlers/signup.js +135 -0
  49. package/dist/auth/handlers/signup.mjs +100 -0
  50. package/dist/auth/handlers/signup_with_thirdparty.d.mts +17 -0
  51. package/dist/auth/handlers/signup_with_thirdparty.d.ts +17 -0
  52. package/dist/auth/handlers/signup_with_thirdparty.js +123 -0
  53. package/dist/auth/handlers/signup_with_thirdparty.mjs +98 -0
  54. package/dist/auth/handlers/thirdparty_auth_callback.d.mts +16 -0
  55. package/dist/auth/handlers/thirdparty_auth_callback.d.ts +16 -0
  56. package/dist/{route/auth/callback/[provider]/route.js → auth/handlers/thirdparty_auth_callback.js} +54 -45
  57. package/dist/{route/auth/callback/[provider]/route.mjs → auth/handlers/thirdparty_auth_callback.mjs} +49 -40
  58. package/dist/{auth-kit/jwt.d.mts → auth/jwt_manager.d.mts} +11 -1
  59. package/dist/{auth-kit/jwt.d.ts → auth/jwt_manager.d.ts} +11 -1
  60. package/dist/{auth-kit/jwt.js → auth/jwt_manager.js} +25 -11
  61. package/dist/{auth-kit/jwt.mjs → auth/jwt_manager.mjs} +22 -8
  62. package/dist/auth/kakao_auth.d.mts +27 -0
  63. package/dist/auth/kakao_auth.d.ts +27 -0
  64. package/dist/auth/kakao_auth.js +56 -0
  65. package/dist/auth/kakao_auth.mjs +31 -0
  66. package/dist/auth/thirdparty_auth.d.mts +41 -0
  67. package/dist/auth/thirdparty_auth.d.ts +41 -0
  68. package/dist/{auth-kit/kakao_auth.js → auth/thirdparty_auth.js} +31 -33
  69. package/dist/{auth-kit/kakao_auth.mjs → auth/thirdparty_auth.mjs} +26 -28
  70. package/dist/{auth-kit → auth}/with_auth.d.mts +5 -6
  71. package/dist/{auth-kit → auth}/with_auth.d.ts +5 -6
  72. package/dist/{auth-kit → auth}/with_auth.js +26 -10
  73. package/dist/auth/with_auth.mjs +63 -0
  74. package/dist/date.d.mts +2 -0
  75. package/dist/date.d.ts +2 -0
  76. package/dist/date.js +4 -2
  77. package/dist/date.mjs +2 -1
  78. package/dist/{file-kit → file}/cdn.js +1 -1
  79. package/dist/{file-kit → file}/cdn.mjs +1 -1
  80. package/dist/{file-kit → file}/client/drop_file_input.js +3 -3
  81. package/dist/{file-kit → file}/client/drop_file_input.mjs +3 -3
  82. package/dist/{file-kit → file}/client/file_upload_button.js +1 -1
  83. package/dist/{file-kit → file}/client/file_upload_button.mjs +1 -1
  84. package/dist/{file-kit → file}/client/file_uploader.js +3 -3
  85. package/dist/{file-kit → file}/client/file_uploader.mjs +2 -2
  86. package/dist/{file-kit → file}/client/format_size.js +1 -1
  87. package/dist/{file-kit → file}/client/format_size.mjs +1 -1
  88. package/dist/{file-kit → file}/client/metadata.js +1 -1
  89. package/dist/{file-kit → file}/client/metadata.mjs +1 -1
  90. package/dist/{file-kit/repository.d.mts → file/file_repository.d.mts} +4 -4
  91. package/dist/{file-kit/repository.d.ts → file/file_repository.d.ts} +4 -4
  92. package/dist/{auth-kit/repository.js → file/file_repository.js} +3 -3
  93. package/dist/file/file_service.d.mts +32 -0
  94. package/dist/file/file_service.d.ts +32 -0
  95. package/dist/{file-kit → file}/file_service.js +27 -21
  96. package/dist/file/file_service.mjs +41 -0
  97. package/dist/file/handlers/delete_file.d.mts +17 -0
  98. package/dist/file/handlers/delete_file.d.ts +17 -0
  99. package/dist/{route/api/files/[fileId]/route.js → file/handlers/delete_file.js} +15 -15
  100. package/dist/{route/api/files/[fileId]/route.mjs → file/handlers/delete_file.mjs} +10 -10
  101. package/dist/file/handlers/upload_file.d.mts +16 -0
  102. package/dist/file/handlers/upload_file.d.ts +16 -0
  103. package/dist/{route/api/files/route.js → file/handlers/upload_file.js} +13 -13
  104. package/dist/{route/api/files/route.mjs → file/handlers/upload_file.mjs} +8 -8
  105. package/dist/{file-kit → file}/object_storage.d.mts +3 -1
  106. package/dist/{file-kit → file}/object_storage.d.ts +3 -1
  107. package/dist/{file-kit → file}/object_storage.js +2 -2
  108. package/dist/{file-kit → file}/object_storage.mjs +2 -2
  109. package/dist/{file-kit → file}/responsive_image.d.mts +4 -4
  110. package/dist/{file-kit → file}/responsive_image.d.ts +4 -4
  111. package/dist/{file-kit → file}/responsive_image.js +18 -9
  112. package/dist/{file-kit → file}/responsive_image.mjs +18 -9
  113. package/dist/{http-kit → http}/index.js +5 -5
  114. package/dist/{http-kit → http}/index.mjs +1 -1
  115. package/dist/{http-kit → http}/response.js +1 -1
  116. package/dist/{http-kit → http}/response.mjs +1 -1
  117. package/dist/index.d.mts +1 -0
  118. package/dist/index.d.ts +1 -0
  119. package/dist/index.js +2 -0
  120. package/dist/index.mjs +1 -0
  121. package/dist/route/api.d.mts +15 -25
  122. package/dist/route/api.d.ts +15 -25
  123. package/dist/route/api.js +325 -178
  124. package/dist/route/api.mjs +314 -177
  125. package/dist/{seo-kit → seo}/seo.js +1 -1
  126. package/dist/{seo-kit → seo}/seo.mjs +1 -1
  127. package/package.json +74 -74
  128. package/dist/auth-kit/apple_auth.d.mts +0 -24
  129. package/dist/auth-kit/apple_auth.d.ts +0 -24
  130. package/dist/auth-kit/apple_auth.mjs +0 -50
  131. package/dist/auth-kit/client/google_login_button.d.mts +0 -9
  132. package/dist/auth-kit/client/google_login_button.d.ts +0 -9
  133. package/dist/auth-kit/client/google_login_button.mjs +0 -32
  134. package/dist/auth-kit/client/logout.d.mts +0 -3
  135. package/dist/auth-kit/client/logout.d.ts +0 -3
  136. package/dist/auth-kit/client/logout.js +0 -49
  137. package/dist/auth-kit/client/logout.mjs +0 -24
  138. package/dist/auth-kit/google_auth.d.mts +0 -27
  139. package/dist/auth-kit/google_auth.d.ts +0 -27
  140. package/dist/auth-kit/kakao_auth.d.mts +0 -24
  141. package/dist/auth-kit/kakao_auth.d.ts +0 -24
  142. package/dist/auth-kit/with_auth.mjs +0 -47
  143. package/dist/file-kit/file_service.d.mts +0 -26
  144. package/dist/file-kit/file_service.d.ts +0 -26
  145. package/dist/file-kit/file_service.mjs +0 -35
  146. package/dist/route/api/auth/login/_provider_/route.d.mts +0 -20
  147. package/dist/route/api/auth/login/_provider_/route.d.ts +0 -20
  148. package/dist/route/api/auth/login/route.d.mts +0 -14
  149. package/dist/route/api/auth/login/route.d.ts +0 -14
  150. package/dist/route/api/auth/logout/route.d.mts +0 -14
  151. package/dist/route/api/auth/logout/route.d.ts +0 -14
  152. package/dist/route/api/auth/refresh/route.d.mts +0 -13
  153. package/dist/route/api/auth/refresh/route.d.ts +0 -13
  154. package/dist/route/api/auth/route.d.mts +0 -13
  155. package/dist/route/api/auth/route.d.ts +0 -13
  156. package/dist/route/api/files/_fileId_/route.d.mts +0 -17
  157. package/dist/route/api/files/_fileId_/route.d.ts +0 -17
  158. package/dist/route/api/files/route.d.mts +0 -16
  159. package/dist/route/api/files/route.d.ts +0 -16
  160. package/dist/route/auth/callback/_provider_/route.d.mts +0 -20
  161. package/dist/route/auth/callback/_provider_/route.d.ts +0 -20
  162. /package/dist/{auth-kit/repository.mjs → auth/auth_repository.mjs} +0 -0
  163. /package/dist/{auth-kit → auth}/client/redirect_page.d.mts +0 -0
  164. /package/dist/{auth-kit → auth}/client/redirect_page.d.ts +0 -0
  165. /package/dist/{file-kit → file}/cdn.d.mts +0 -0
  166. /package/dist/{file-kit → file}/cdn.d.ts +0 -0
  167. /package/dist/{file-kit → file}/client/drop_file_input.d.mts +0 -0
  168. /package/dist/{file-kit → file}/client/drop_file_input.d.ts +0 -0
  169. /package/dist/{file-kit → file}/client/file_upload_button.d.mts +0 -0
  170. /package/dist/{file-kit → file}/client/file_upload_button.d.ts +0 -0
  171. /package/dist/{file-kit → file}/client/file_uploader.d.mts +0 -0
  172. /package/dist/{file-kit → file}/client/file_uploader.d.ts +0 -0
  173. /package/dist/{file-kit → file}/client/format_size.d.mts +0 -0
  174. /package/dist/{file-kit → file}/client/format_size.d.ts +0 -0
  175. /package/dist/{file-kit → file}/client/metadata.d.mts +0 -0
  176. /package/dist/{file-kit → file}/client/metadata.d.ts +0 -0
  177. /package/dist/{file-kit/repository.mjs → file/file_repository.mjs} +0 -0
  178. /package/dist/{http-kit → http}/index.d.mts +0 -0
  179. /package/dist/{http-kit → http}/index.d.ts +0 -0
  180. /package/dist/{http-kit → http}/response.d.mts +0 -0
  181. /package/dist/{http-kit → http}/response.d.ts +0 -0
  182. /package/dist/{seo-kit → seo}/seo.d.mts +0 -0
  183. /package/dist/{seo-kit → seo}/seo.d.ts +0 -0
@@ -1,6 +1,5 @@
1
- // src/auth-kit/auth_service.ts
1
+ // src/auth/auth_service.ts
2
2
  import bcryptjs from "bcryptjs";
3
- import { v4 } from "uuid";
4
3
  import { createCookie } from "react-router";
5
4
  var ACCESS_TOKEN_KEY = "access_token";
6
5
  var REFRESH_TOKEN_KEY = "refresh_token";
@@ -17,22 +16,22 @@ var REFRESH_TOKEN_COOKIE = createCookie(REFRESH_TOKEN_KEY, {
17
16
  sameSite: "strict"
18
17
  });
19
18
  var AuthService = class {
20
- repository;
21
- JWT_MANAGER;
22
- OBJECT_STORAGE;
19
+ authRepository;
20
+ jwtManager;
21
+ objectStorage;
23
22
  constructor({
24
- repository,
25
- JWT_MANAGER,
26
- OBJECT_STORAGE
23
+ authRepository,
24
+ jwtManager,
25
+ objectStorage
27
26
  }) {
28
- this.repository = repository;
29
- this.JWT_MANAGER = JWT_MANAGER;
30
- this.OBJECT_STORAGE = OBJECT_STORAGE;
27
+ this.authRepository = authRepository;
28
+ this.jwtManager = jwtManager;
29
+ this.objectStorage = objectStorage;
31
30
  }
32
31
  async verify(request) {
33
32
  const accessToken = await this.getAccessTokenFromRequest(request);
34
33
  if (accessToken) {
35
- return this.JWT_MANAGER.verifyAccessToken(accessToken);
34
+ return this.jwtManager.verifyAccessToken(accessToken);
36
35
  }
37
36
  }
38
37
  async verifyOrRefresh(request) {
@@ -68,7 +67,7 @@ var AuthService = class {
68
67
  refreshToken
69
68
  );
70
69
  await this.getAccessTokenSetCookie(refreshedAccessToken);
71
- const payload = this.JWT_MANAGER.decode(refreshedAccessToken);
70
+ const payload = this.jwtManager.decode(refreshedAccessToken);
72
71
  if (payload) {
73
72
  return payload;
74
73
  }
@@ -81,14 +80,14 @@ var AuthService = class {
81
80
  }
82
81
  }
83
82
  async signIn({ id, password }) {
84
- const credential = await this.repository.findCredentialById(id);
83
+ const credential = await this.authRepository.findCredentialById(id);
85
84
  if (!credential) {
86
85
  throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
87
86
  }
88
87
  if (!await bcryptjs.compare(password, credential.password)) {
89
88
  throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
90
89
  }
91
- const user = await this.repository.findUserById(credential.userId);
90
+ const user = await this.authRepository.findUserById(credential.userId);
92
91
  if (!user) {
93
92
  throw Error("\uD68C\uC6D0 \uC815\uBCF4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
94
93
  }
@@ -99,19 +98,19 @@ var AuthService = class {
99
98
  };
100
99
  }
101
100
  async issueAccessToken(user) {
102
- return this.JWT_MANAGER.signAccessToken({
101
+ return this.jwtManager.signAccessToken({
103
102
  userId: user.id,
104
103
  role: user.role,
105
104
  name: user.name
106
105
  });
107
106
  }
108
107
  async issueTokenPair(user) {
109
- const refreshToken = await this.JWT_MANAGER.signRefreshToken({
108
+ const refreshToken = await this.jwtManager.signRefreshToken({
110
109
  userId: user.id,
111
110
  role: user.role,
112
111
  name: user.name
113
112
  });
114
- await this.repository.updateUserRefreshToken(
113
+ await this.authRepository.updateUserRefreshToken(
115
114
  user.id,
116
115
  await bcryptjs.hash(refreshToken, 10)
117
116
  );
@@ -119,7 +118,7 @@ var AuthService = class {
119
118
  return { refreshToken, accessToken };
120
119
  }
121
120
  async refreshAccessToken(refreshToken) {
122
- const payload = await this.JWT_MANAGER.verifyRefreshToken(refreshToken);
121
+ const payload = await this.jwtManager.verifyRefreshToken(refreshToken);
123
122
  if (!payload) {
124
123
  throw new Error("\uD1A0\uD070\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
125
124
  }
@@ -127,7 +126,7 @@ var AuthService = class {
127
126
  if (typeof userId !== "string") {
128
127
  throw new Error("\uD1A0\uD070\uC774 \uC704\uC870\uB418\uC5C8\uC2B5\uB2C8\uB2E4.");
129
128
  }
130
- const user = await this.repository.findUserById(userId);
129
+ const user = await this.authRepository.findUserById(userId);
131
130
  if (!user) {
132
131
  throw Error("\uC774\uC6A9\uC790\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.");
133
132
  }
@@ -142,78 +141,26 @@ var AuthService = class {
142
141
  }
143
142
  async getAccessTokenSetCookie(accessToken) {
144
143
  return ACCESS_TOKEN_COOKIE.serialize(accessToken, {
145
- expires: accessToken ? this.JWT_MANAGER.getExpirationTime(accessToken) : /* @__PURE__ */ new Date(0)
144
+ expires: accessToken ? this.jwtManager.getExpirationTime(accessToken) : /* @__PURE__ */ new Date(0)
146
145
  });
147
146
  }
148
147
  async getRefreshTokenSetCookie(refreshToken) {
149
148
  return REFRESH_TOKEN_COOKIE.serialize(refreshToken, {
150
- expires: refreshToken ? this.JWT_MANAGER.getExpirationTime(refreshToken) : /* @__PURE__ */ new Date(0)
149
+ expires: refreshToken ? this.jwtManager.getExpirationTime(refreshToken) : /* @__PURE__ */ new Date(0)
151
150
  });
152
151
  }
153
152
  async findUser(provider, info) {
154
- const thirdPartyAuth = await this.repository.findThirdPartyAuth(
153
+ const thirdPartyAuth = await this.authRepository.findThirdPartyAuth(
155
154
  provider,
156
155
  info.id
157
156
  );
158
157
  if (thirdPartyAuth) {
159
- const user = await this.repository.findUserById(thirdPartyAuth.userId);
158
+ const user = await this.authRepository.findUserById(thirdPartyAuth.userId);
160
159
  if (user) {
161
160
  return user;
162
161
  }
163
162
  }
164
163
  }
165
- async getOrCreateUser(provider, info) {
166
- const thirdPartyAuth = await this.repository.findThirdPartyAuth(
167
- provider,
168
- info.id
169
- );
170
- if (thirdPartyAuth) {
171
- const user = await this.repository.findUserById(thirdPartyAuth.userId);
172
- if (user) {
173
- return user;
174
- }
175
- }
176
- const userId = v4();
177
- const email = info.email;
178
- const name = info.name || "\uC775\uBA85";
179
- const picture = info.picture;
180
- const profileImageId = await this.savePicture(picture) || null;
181
- const result = await this.repository.createUser({
182
- id: userId,
183
- role: "user",
184
- profileImageId,
185
- name,
186
- email
187
- });
188
- await this.repository.createThirdPartyAuth({
189
- id: info.id,
190
- provider,
191
- userId
192
- });
193
- return result;
194
- }
195
- async savePicture(picture) {
196
- if (!picture) {
197
- return;
198
- }
199
- const res = await fetch(picture);
200
- if (!res.ok) {
201
- return;
202
- }
203
- const buffer = await res.arrayBuffer();
204
- const id = v4();
205
- const key = `/users/${id}/picture`;
206
- await this.OBJECT_STORAGE.put(key, Buffer.from(buffer));
207
- await this.repository.createFile({
208
- id,
209
- name: "picture",
210
- type: "image/*",
211
- key,
212
- size: buffer.byteLength,
213
- metadata: {}
214
- });
215
- return id;
216
- }
217
164
  };
218
165
  export {
219
166
  ACCESS_TOKEN_COOKIE,
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+
3
+ declare function GoogleLoginButton({ className, }: {
4
+ className?: string;
5
+ }): React.JSX.Element;
6
+
7
+ export { GoogleLoginButton };
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+
3
+ declare function GoogleLoginButton({ className, }: {
4
+ className?: string;
5
+ }): React.JSX.Element;
6
+
7
+ export { GoogleLoginButton };
@@ -27,38 +27,43 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
- // src/auth-kit/client/google_login_button.tsx
30
+ // src/auth/client/google_login_button.tsx
31
31
  var google_login_button_exports = {};
32
32
  __export(google_login_button_exports, {
33
33
  GoogleLoginButton: () => GoogleLoginButton
34
34
  });
35
35
  module.exports = __toCommonJS(google_login_button_exports);
36
- var import_react = __toESM(require("react"));
36
+ var import_react3 = __toESM(require("react"));
37
37
  var import_fc = require("react-icons/fc");
38
+ var import_react_router2 = require("react-router");
39
+
40
+ // src/auth/client/provider.tsx
41
+ var import_react = __toESM(require("react"));
42
+ var import_react2 = require("react");
38
43
  var import_react_router = require("react-router");
44
+ var AuthContext = (0, import_react2.createContext)({});
45
+ var useAuth = () => {
46
+ return (0, import_react2.useContext)(AuthContext);
47
+ };
48
+
49
+ // src/auth/client/google_login_button.tsx
39
50
  function GoogleLoginButton({
40
- className = "max-w-[300px] w-full",
41
- GOOGLE_CLIENT_ID,
42
- GOOGLE_REDIRECT_URI
51
+ className = "max-w-[300px] w-full"
43
52
  }) {
44
- const [searchParams] = (0, import_react_router.useSearchParams)();
53
+ const { loginWithGoogle } = useAuth();
54
+ const [searchParams] = (0, import_react_router2.useSearchParams)();
45
55
  const redirectUrl = searchParams.get("redirectUrl") || "";
46
- const googleClientId = GOOGLE_CLIENT_ID || "";
47
- const googleRedirectUrl = GOOGLE_REDIRECT_URI || "";
48
- const href = new URL("https://accounts.google.com/o/oauth2/v2/auth");
49
- href.searchParams.append("client_id", googleClientId);
50
- href.searchParams.append("redirect_uri", googleRedirectUrl);
51
- href.searchParams.append("response_type", "code");
52
- href.searchParams.append("scope", "email profile");
53
- href.searchParams.append("state", redirectUrl);
54
- return /* @__PURE__ */ import_react.default.createElement("div", { className }, /* @__PURE__ */ import_react.default.createElement(
55
- "a",
56
+ return /* @__PURE__ */ import_react3.default.createElement("div", { className }, /* @__PURE__ */ import_react3.default.createElement(
57
+ "button",
56
58
  {
57
- href: href.toString(),
59
+ type: "button",
60
+ onClick: () => {
61
+ loginWithGoogle(redirectUrl);
62
+ },
58
63
  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"
59
64
  },
60
- /* @__PURE__ */ import_react.default.createElement(import_fc.FcGoogle, null),
61
- /* @__PURE__ */ import_react.default.createElement("p", { className: "text-[14px] text-black absolute left-0 right-0 text-center" }, "\uAD6C\uAE00\uB85C \uACC4\uC18D\uD558\uAE30")
65
+ /* @__PURE__ */ import_react3.default.createElement(import_fc.FcGoogle, null),
66
+ /* @__PURE__ */ import_react3.default.createElement("p", { className: "text-[14px] text-black absolute left-0 right-0 text-center" }, "\uAD6C\uAE00\uB85C \uACC4\uC18D\uD558\uAE30")
62
67
  ));
63
68
  }
64
69
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,37 @@
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
+ };
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+
3
+ type AuthContextValue = {
4
+ auth?: {
5
+ userId: string;
6
+ };
7
+ login: (id: string, password: string) => Promise<void>;
8
+ loginWithGoogle: (redirectUrl?: string) => Promise<void>;
9
+ logout: () => Promise<void>;
10
+ requestResetPassword: (email: string) => Promise<boolean>;
11
+ resetPassword: (token: string, password: string, passwordConfirm: string) => Promise<boolean>;
12
+ };
13
+ declare const AuthContext: React.Context<AuthContextValue>;
14
+ declare const useAuth: () => AuthContextValue;
15
+ declare function AuthProvider({ children, googleAuth }: {
16
+ children: React.ReactNode;
17
+ googleAuth?: {
18
+ googleClientId: string;
19
+ googleRedirectUrl: string;
20
+ };
21
+ }): React.JSX.Element;
22
+
23
+ export { AuthContext, type AuthContextValue, AuthProvider as default, useAuth };
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+
3
+ type AuthContextValue = {
4
+ auth?: {
5
+ userId: string;
6
+ };
7
+ login: (id: string, password: string) => Promise<void>;
8
+ loginWithGoogle: (redirectUrl?: string) => Promise<void>;
9
+ logout: () => Promise<void>;
10
+ requestResetPassword: (email: string) => Promise<boolean>;
11
+ resetPassword: (token: string, password: string, passwordConfirm: string) => Promise<boolean>;
12
+ };
13
+ declare const AuthContext: React.Context<AuthContextValue>;
14
+ declare const useAuth: () => AuthContextValue;
15
+ declare function AuthProvider({ children, googleAuth }: {
16
+ children: React.ReactNode;
17
+ googleAuth?: {
18
+ googleClientId: string;
19
+ googleRedirectUrl: string;
20
+ };
21
+ }): React.JSX.Element;
22
+
23
+ export { AuthContext, type AuthContextValue, AuthProvider as default, useAuth };
@@ -0,0 +1,137 @@
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({ children, googleAuth }) {
46
+ const data = (0, import_react_router.useRouteLoaderData)("root");
47
+ const auth = data?.AUTH;
48
+ const navigate = (0, import_react_router.useNavigate)();
49
+ const login = async (id, password) => {
50
+ const res = await fetch("/api/auth/login", {
51
+ method: "POST",
52
+ headers: {
53
+ "Content-Type": "application/json"
54
+ },
55
+ body: JSON.stringify({ id, password })
56
+ });
57
+ if (res.ok) {
58
+ navigate("/");
59
+ } else {
60
+ const { message } = await res.json();
61
+ alert(message);
62
+ }
63
+ };
64
+ const loginWithGoogle = async (redirectUrl = "/") => {
65
+ if (!googleAuth) {
66
+ alert("\uAD6C\uAE00 \uB85C\uADF8\uC778 \uC124\uC815\uC774 \uB418\uC5B4\uC788\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
67
+ return;
68
+ }
69
+ const { googleClientId, googleRedirectUrl } = googleAuth;
70
+ const href = new URL("https://accounts.google.com/o/oauth2/v2/auth");
71
+ href.searchParams.append("client_id", googleClientId);
72
+ href.searchParams.append("redirect_uri", googleRedirectUrl);
73
+ href.searchParams.append("response_type", "code");
74
+ href.searchParams.append("scope", "email profile");
75
+ href.searchParams.append("state", redirectUrl);
76
+ window.location.href = href.toString();
77
+ };
78
+ const logout = async () => {
79
+ const ok = confirm("\uC815\uB9D0 \uB85C\uADF8\uC544\uC6C3 \uD558\uC2DC\uACA0\uC2B5\uB2C8\uAE4C?");
80
+ if (!ok) {
81
+ return;
82
+ }
83
+ const res = await fetch("/api/auth/logout", {
84
+ method: "POST"
85
+ });
86
+ if (res.ok) {
87
+ navigate("/");
88
+ } else {
89
+ const { message } = await res.json();
90
+ alert(message);
91
+ }
92
+ };
93
+ const requestResetPassword = async (email) => {
94
+ const response = await fetch("/api/find-password", {
95
+ method: "POST",
96
+ headers: {
97
+ "Content-Type": "application/json"
98
+ },
99
+ body: JSON.stringify({ email })
100
+ });
101
+ if (!response.ok) {
102
+ const { message } = await response.json();
103
+ alert(message);
104
+ return false;
105
+ }
106
+ return true;
107
+ };
108
+ const resetPassword = async (token, password, passwordConfirm) => {
109
+ const response = await fetch("/api/reset-password", {
110
+ method: "POST",
111
+ headers: {
112
+ "Content-Type": "application/json"
113
+ },
114
+ body: JSON.stringify({ token, password, passwordConfirm })
115
+ });
116
+ if (!response.ok) {
117
+ const { message } = await response.json();
118
+ alert(message);
119
+ return false;
120
+ }
121
+ return true;
122
+ };
123
+ const authContextValue = {
124
+ auth,
125
+ login,
126
+ logout,
127
+ loginWithGoogle,
128
+ requestResetPassword,
129
+ resetPassword
130
+ };
131
+ return /* @__PURE__ */ import_react.default.createElement(AuthContext.Provider, { value: authContextValue }, children);
132
+ }
133
+ // Annotate the CommonJS export names for ESM import in node:
134
+ 0 && (module.exports = {
135
+ AuthContext,
136
+ useAuth
137
+ });
@@ -0,0 +1,101 @@
1
+ // src/auth/client/provider.tsx
2
+ import React from "react";
3
+ import { createContext, useContext } from "react";
4
+ import { useNavigate, useRouteLoaderData } from "react-router";
5
+ var AuthContext = createContext({});
6
+ var useAuth = () => {
7
+ return useContext(AuthContext);
8
+ };
9
+ function AuthProvider({ children, googleAuth }) {
10
+ const data = useRouteLoaderData("root");
11
+ const auth = data?.AUTH;
12
+ const navigate = useNavigate();
13
+ const login = async (id, password) => {
14
+ const res = await fetch("/api/auth/login", {
15
+ method: "POST",
16
+ headers: {
17
+ "Content-Type": "application/json"
18
+ },
19
+ body: JSON.stringify({ id, password })
20
+ });
21
+ if (res.ok) {
22
+ navigate("/");
23
+ } else {
24
+ const { message } = await res.json();
25
+ alert(message);
26
+ }
27
+ };
28
+ const loginWithGoogle = async (redirectUrl = "/") => {
29
+ if (!googleAuth) {
30
+ alert("\uAD6C\uAE00 \uB85C\uADF8\uC778 \uC124\uC815\uC774 \uB418\uC5B4\uC788\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
31
+ return;
32
+ }
33
+ const { googleClientId, googleRedirectUrl } = googleAuth;
34
+ const href = new URL("https://accounts.google.com/o/oauth2/v2/auth");
35
+ href.searchParams.append("client_id", googleClientId);
36
+ href.searchParams.append("redirect_uri", googleRedirectUrl);
37
+ href.searchParams.append("response_type", "code");
38
+ href.searchParams.append("scope", "email profile");
39
+ href.searchParams.append("state", redirectUrl);
40
+ window.location.href = href.toString();
41
+ };
42
+ const logout = async () => {
43
+ const ok = confirm("\uC815\uB9D0 \uB85C\uADF8\uC544\uC6C3 \uD558\uC2DC\uACA0\uC2B5\uB2C8\uAE4C?");
44
+ if (!ok) {
45
+ return;
46
+ }
47
+ const res = await fetch("/api/auth/logout", {
48
+ method: "POST"
49
+ });
50
+ if (res.ok) {
51
+ navigate("/");
52
+ } else {
53
+ const { message } = await res.json();
54
+ alert(message);
55
+ }
56
+ };
57
+ const requestResetPassword = async (email) => {
58
+ const response = await fetch("/api/find-password", {
59
+ method: "POST",
60
+ headers: {
61
+ "Content-Type": "application/json"
62
+ },
63
+ body: JSON.stringify({ email })
64
+ });
65
+ if (!response.ok) {
66
+ const { message } = await response.json();
67
+ alert(message);
68
+ return false;
69
+ }
70
+ return true;
71
+ };
72
+ const resetPassword = async (token, password, passwordConfirm) => {
73
+ const response = await fetch("/api/reset-password", {
74
+ method: "POST",
75
+ headers: {
76
+ "Content-Type": "application/json"
77
+ },
78
+ body: JSON.stringify({ token, password, passwordConfirm })
79
+ });
80
+ if (!response.ok) {
81
+ const { message } = await response.json();
82
+ alert(message);
83
+ return false;
84
+ }
85
+ return true;
86
+ };
87
+ const authContextValue = {
88
+ auth,
89
+ login,
90
+ logout,
91
+ loginWithGoogle,
92
+ requestResetPassword,
93
+ resetPassword
94
+ };
95
+ return /* @__PURE__ */ React.createElement(AuthContext.Provider, { value: authContextValue }, children);
96
+ }
97
+ export {
98
+ AuthContext,
99
+ AuthProvider as default,
100
+ useAuth
101
+ };
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
- // src/auth-kit/client/redirect_page.tsx
30
+ // src/auth/client/redirect_page.tsx
31
31
  var redirect_page_exports = {};
32
32
  __export(redirect_page_exports, {
33
33
  RedirectPage: () => RedirectPage
@@ -1,4 +1,4 @@
1
- // src/auth-kit/client/redirect_page.tsx
1
+ // src/auth/client/redirect_page.tsx
2
2
  import React from "react";
3
3
  import { useEffect } from "react";
4
4
  import { useNavigate } from "react-router";
@@ -0,0 +1,33 @@
1
+ import { ThirdpartyAuth, ThirdpartyAuthService } from './thirdparty_auth.mjs';
2
+ import './auth_service.mjs';
3
+ import 'jose';
4
+ import 'react-router';
5
+ import './jwt_manager.mjs';
6
+ import '../file/object_storage.mjs';
7
+ import '@aws-sdk/client-s3';
8
+ import './auth_repository.mjs';
9
+
10
+ declare class GoogleAuth implements ThirdpartyAuth {
11
+ thirdpartyAuth: ThirdpartyAuthService;
12
+ googleClientId: string;
13
+ googleClientSecret: string;
14
+ googleRedirectUri: string;
15
+ constructor({ thirdpartyAuth, googleClientId, googleClientSecret, googleRedirectUri, }: {
16
+ thirdpartyAuth: ThirdpartyAuthService;
17
+ googleClientId: string;
18
+ googleClientSecret: string;
19
+ googleRedirectUri: string;
20
+ });
21
+ login(code: string): Promise<{
22
+ user: {
23
+ id: string;
24
+ role: string;
25
+ name: string;
26
+ refreshToken: string | null;
27
+ };
28
+ accessToken: string;
29
+ refreshToken: string;
30
+ }>;
31
+ }
32
+
33
+ export { GoogleAuth };
@@ -0,0 +1,33 @@
1
+ import { ThirdpartyAuth, ThirdpartyAuthService } from './thirdparty_auth.js';
2
+ import './auth_service.js';
3
+ import 'jose';
4
+ import 'react-router';
5
+ import './jwt_manager.js';
6
+ import '../file/object_storage.js';
7
+ import '@aws-sdk/client-s3';
8
+ import './auth_repository.js';
9
+
10
+ declare class GoogleAuth implements ThirdpartyAuth {
11
+ thirdpartyAuth: ThirdpartyAuthService;
12
+ googleClientId: string;
13
+ googleClientSecret: string;
14
+ googleRedirectUri: string;
15
+ constructor({ thirdpartyAuth, googleClientId, googleClientSecret, googleRedirectUri, }: {
16
+ thirdpartyAuth: ThirdpartyAuthService;
17
+ googleClientId: string;
18
+ googleClientSecret: string;
19
+ googleRedirectUri: string;
20
+ });
21
+ login(code: string): Promise<{
22
+ user: {
23
+ id: string;
24
+ role: string;
25
+ name: string;
26
+ refreshToken: string | null;
27
+ };
28
+ accessToken: string;
29
+ refreshToken: string;
30
+ }>;
31
+ }
32
+
33
+ export { GoogleAuth };