dn-react-router-toolkit 0.1.11 → 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 +12 -22
  9. package/dist/{auth-kit → auth}/auth_service.d.ts +12 -22
  10. package/dist/{auth-kit → auth}/auth_service.js +30 -77
  11. package/dist/{auth-kit → auth}/auth_service.mjs +30 -77
  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 -42
  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 -67
  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
- const accessToken = request?.headers.get("Authorization")?.replace("Bearer ", "") || await this.getAccessTokenFromCookies(request);
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) {
@@ -42,6 +41,12 @@ var AuthService = class {
42
41
  }
43
42
  return this.refresh(request);
44
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
+ }
45
50
  async getAccessTokenFromCookies(request) {
46
51
  const accessToken = await ACCESS_TOKEN_COOKIE.parse(
47
52
  request.headers.get("cookie")
@@ -62,7 +67,7 @@ var AuthService = class {
62
67
  refreshToken
63
68
  );
64
69
  await this.getAccessTokenSetCookie(refreshedAccessToken);
65
- const payload = this.JWT_MANAGER.decode(refreshedAccessToken);
70
+ const payload = this.jwtManager.decode(refreshedAccessToken);
66
71
  if (payload) {
67
72
  return payload;
68
73
  }
@@ -75,14 +80,14 @@ var AuthService = class {
75
80
  }
76
81
  }
77
82
  async signIn({ id, password }) {
78
- const credential = await this.repository.findCredentialById(id);
83
+ const credential = await this.authRepository.findCredentialById(id);
79
84
  if (!credential) {
80
85
  throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
81
86
  }
82
87
  if (!await bcryptjs.compare(password, credential.password)) {
83
88
  throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
84
89
  }
85
- const user = await this.repository.findUserById(credential.userId);
90
+ const user = await this.authRepository.findUserById(credential.userId);
86
91
  if (!user) {
87
92
  throw Error("\uD68C\uC6D0 \uC815\uBCF4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
88
93
  }
@@ -93,19 +98,19 @@ var AuthService = class {
93
98
  };
94
99
  }
95
100
  async issueAccessToken(user) {
96
- return this.JWT_MANAGER.signAccessToken({
101
+ return this.jwtManager.signAccessToken({
97
102
  userId: user.id,
98
103
  role: user.role,
99
104
  name: user.name
100
105
  });
101
106
  }
102
107
  async issueTokenPair(user) {
103
- const refreshToken = await this.JWT_MANAGER.signRefreshToken({
108
+ const refreshToken = await this.jwtManager.signRefreshToken({
104
109
  userId: user.id,
105
110
  role: user.role,
106
111
  name: user.name
107
112
  });
108
- await this.repository.updateUserRefreshToken(
113
+ await this.authRepository.updateUserRefreshToken(
109
114
  user.id,
110
115
  await bcryptjs.hash(refreshToken, 10)
111
116
  );
@@ -113,7 +118,7 @@ var AuthService = class {
113
118
  return { refreshToken, accessToken };
114
119
  }
115
120
  async refreshAccessToken(refreshToken) {
116
- const payload = await this.JWT_MANAGER.verifyRefreshToken(refreshToken);
121
+ const payload = await this.jwtManager.verifyRefreshToken(refreshToken);
117
122
  if (!payload) {
118
123
  throw new Error("\uD1A0\uD070\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
119
124
  }
@@ -121,7 +126,7 @@ var AuthService = class {
121
126
  if (typeof userId !== "string") {
122
127
  throw new Error("\uD1A0\uD070\uC774 \uC704\uC870\uB418\uC5C8\uC2B5\uB2C8\uB2E4.");
123
128
  }
124
- const user = await this.repository.findUserById(userId);
129
+ const user = await this.authRepository.findUserById(userId);
125
130
  if (!user) {
126
131
  throw Error("\uC774\uC6A9\uC790\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.");
127
132
  }
@@ -136,77 +141,25 @@ var AuthService = class {
136
141
  }
137
142
  async getAccessTokenSetCookie(accessToken) {
138
143
  return ACCESS_TOKEN_COOKIE.serialize(accessToken, {
139
- expires: accessToken ? this.JWT_MANAGER.getExpirationTime(accessToken) : /* @__PURE__ */ new Date(0)
144
+ expires: accessToken ? this.jwtManager.getExpirationTime(accessToken) : /* @__PURE__ */ new Date(0)
140
145
  });
141
146
  }
142
147
  async getRefreshTokenSetCookie(refreshToken) {
143
148
  return REFRESH_TOKEN_COOKIE.serialize(refreshToken, {
144
- expires: refreshToken ? this.JWT_MANAGER.getExpirationTime(refreshToken) : /* @__PURE__ */ new Date(0)
149
+ expires: refreshToken ? this.jwtManager.getExpirationTime(refreshToken) : /* @__PURE__ */ new Date(0)
145
150
  });
146
151
  }
147
152
  async findUser(provider, info) {
148
- const thirdPartyAuth = await this.repository.findThirdPartyAuth(
149
- provider,
150
- info.id
151
- );
152
- if (thirdPartyAuth) {
153
- const user = await this.repository.findUserById(thirdPartyAuth.userId);
154
- if (user) {
155
- return user;
156
- }
157
- }
158
- }
159
- async getOrCreateUser(provider, info) {
160
- const thirdPartyAuth = await this.repository.findThirdPartyAuth(
153
+ const thirdPartyAuth = await this.authRepository.findThirdPartyAuth(
161
154
  provider,
162
155
  info.id
163
156
  );
164
157
  if (thirdPartyAuth) {
165
- const user = await this.repository.findUserById(thirdPartyAuth.userId);
158
+ const user = await this.authRepository.findUserById(thirdPartyAuth.userId);
166
159
  if (user) {
167
160
  return user;
168
161
  }
169
162
  }
170
- const userId = v4();
171
- const email = info.email;
172
- const name = info.name || "\uC775\uBA85";
173
- const picture = info.picture;
174
- const profileImageId = await this.savePicture(picture) || null;
175
- const result = await this.repository.createUser({
176
- id: userId,
177
- role: "user",
178
- profileImageId,
179
- name,
180
- email
181
- });
182
- await this.repository.createThirdPartyAuth({
183
- id: info.id,
184
- provider,
185
- userId
186
- });
187
- return result;
188
- }
189
- async savePicture(picture) {
190
- if (!picture) {
191
- return;
192
- }
193
- const res = await fetch(picture);
194
- if (!res.ok) {
195
- return;
196
- }
197
- const buffer = await res.arrayBuffer();
198
- const id = v4();
199
- const key = `/users/${id}/picture`;
200
- await this.OBJECT_STORAGE.put(key, Buffer.from(buffer));
201
- await this.repository.createFile({
202
- id,
203
- name: "picture",
204
- type: "image/*",
205
- key,
206
- size: buffer.byteLength,
207
- metadata: {}
208
- });
209
- return id;
210
163
  }
211
164
  };
212
165
  export {
@@ -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 };