dn-react-router-toolkit 0.1.1 → 0.1.3

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 (284) hide show
  1. package/dist/auth-kit/apple_auth.d.mts +24 -0
  2. package/dist/{esm/auth-kit → auth-kit}/apple_auth.d.ts +11 -2
  3. package/dist/auth-kit/apple_auth.js +75 -0
  4. package/dist/auth-kit/apple_auth.mjs +50 -0
  5. package/dist/auth-kit/auth_service.d.mts +73 -0
  6. package/dist/{esm/auth-kit → auth-kit}/auth_service.d.ts +17 -11
  7. package/dist/auth-kit/auth_service.js +257 -0
  8. package/dist/auth-kit/auth_service.mjs +218 -0
  9. package/dist/auth-kit/client/google_login_button.d.mts +9 -0
  10. package/dist/auth-kit/client/google_login_button.d.ts +9 -0
  11. package/dist/auth-kit/client/google_login_button.js +67 -0
  12. package/dist/auth-kit/client/google_login_button.mjs +32 -0
  13. package/dist/auth-kit/client/redirect_page.d.mts +5 -0
  14. package/dist/auth-kit/client/redirect_page.d.ts +5 -0
  15. package/dist/auth-kit/client/redirect_page.js +53 -0
  16. package/dist/auth-kit/client/redirect_page.mjs +18 -0
  17. package/dist/auth-kit/google_auth.d.mts +27 -0
  18. package/dist/{esm/auth-kit → auth-kit}/google_auth.d.ts +11 -2
  19. package/dist/auth-kit/google_auth.js +144 -0
  20. package/dist/auth-kit/google_auth.mjs +117 -0
  21. package/dist/auth-kit/jwt.d.mts +18 -0
  22. package/dist/{esm/auth-kit → auth-kit}/jwt.d.ts +5 -2
  23. package/dist/auth-kit/jwt.js +76 -0
  24. package/dist/auth-kit/jwt.mjs +51 -0
  25. package/dist/auth-kit/kakao_auth.d.mts +24 -0
  26. package/dist/{esm/auth-kit → auth-kit}/kakao_auth.d.ts +11 -2
  27. package/dist/auth-kit/kakao_auth.js +115 -0
  28. package/dist/auth-kit/kakao_auth.mjs +88 -0
  29. package/dist/auth-kit/repository.d.mts +42 -0
  30. package/dist/{esm/auth-kit → auth-kit}/repository.d.ts +3 -1
  31. package/dist/auth-kit/repository.js +18 -0
  32. package/dist/auth-kit/repository.mjs +0 -0
  33. package/dist/auth-kit/with_auth.d.mts +17 -0
  34. package/dist/auth-kit/with_auth.d.ts +17 -0
  35. package/dist/auth-kit/with_auth.js +106 -0
  36. package/dist/auth-kit/with_auth.mjs +69 -0
  37. package/dist/cn.d.mts +3 -0
  38. package/dist/cn.d.ts +3 -0
  39. package/dist/cn.js +32 -0
  40. package/dist/cn.mjs +7 -0
  41. package/dist/components/index.d.mts +5 -0
  42. package/dist/components/index.d.ts +5 -0
  43. package/dist/components/index.js +261 -0
  44. package/dist/components/index.mjs +219 -0
  45. package/dist/components/modal/fullscreen_container.d.mts +7 -0
  46. package/dist/components/modal/fullscreen_container.d.ts +7 -0
  47. package/dist/components/modal/fullscreen_container.js +102 -0
  48. package/dist/components/modal/fullscreen_container.mjs +68 -0
  49. package/dist/components/modal/hooks.d.mts +18 -0
  50. package/dist/components/modal/hooks.d.ts +18 -0
  51. package/dist/components/modal/hooks.js +236 -0
  52. package/dist/components/modal/hooks.mjs +204 -0
  53. package/dist/components/modal/index.d.mts +4 -0
  54. package/dist/components/modal/index.d.ts +4 -0
  55. package/dist/components/modal/index.js +238 -0
  56. package/dist/components/modal/index.mjs +203 -0
  57. package/dist/components/modal/modal.d.mts +13 -0
  58. package/dist/components/modal/modal.d.ts +13 -0
  59. package/dist/components/modal/modal.js +155 -0
  60. package/dist/components/modal/modal.mjs +130 -0
  61. package/dist/components/styles.d.mts +9 -0
  62. package/dist/components/styles.d.ts +9 -0
  63. package/dist/components/styles.js +48 -0
  64. package/dist/components/styles.mjs +17 -0
  65. package/dist/date.d.mts +3 -0
  66. package/dist/date.d.ts +3 -0
  67. package/dist/date.js +63 -0
  68. package/dist/date.mjs +28 -0
  69. package/dist/file-kit/cdn.d.mts +5 -0
  70. package/dist/file-kit/cdn.d.ts +5 -0
  71. package/dist/file-kit/cdn.js +34 -0
  72. package/dist/file-kit/cdn.mjs +9 -0
  73. package/dist/file-kit/client/drop_file_input.d.mts +33 -0
  74. package/dist/{esm/file-kit → file-kit}/client/drop_file_input.d.ts +10 -8
  75. package/dist/file-kit/client/drop_file_input.js +235 -0
  76. package/dist/file-kit/client/drop_file_input.mjs +205 -0
  77. package/dist/file-kit/client/file_uploader.d.mts +13 -0
  78. package/dist/{esm/file-kit → file-kit}/client/file_uploader.d.ts +4 -2
  79. package/dist/file-kit/client/file_uploader.js +115 -0
  80. package/dist/file-kit/client/file_uploader.mjs +90 -0
  81. package/dist/file-kit/file_service.d.mts +26 -0
  82. package/dist/{esm/file-kit → file-kit}/file_service.d.ts +7 -4
  83. package/dist/file-kit/file_service.js +60 -0
  84. package/dist/file-kit/file_service.mjs +35 -0
  85. package/dist/file-kit/object_storage.d.mts +17 -0
  86. package/dist/{esm/file-kit → file-kit}/object_storage.d.ts +6 -2
  87. package/dist/file-kit/object_storage.js +78 -0
  88. package/dist/file-kit/object_storage.mjs +57 -0
  89. package/dist/file-kit/repository.d.mts +16 -0
  90. package/dist/{esm/file-kit → file-kit}/repository.d.ts +3 -1
  91. package/dist/file-kit/repository.js +18 -0
  92. package/dist/file-kit/repository.mjs +0 -0
  93. package/dist/file-kit/responsive_image.d.mts +20 -0
  94. package/dist/file-kit/responsive_image.d.ts +20 -0
  95. package/dist/file-kit/responsive_image.js +123 -0
  96. package/dist/file-kit/responsive_image.mjs +87 -0
  97. package/dist/http-kit/index.d.mts +1 -0
  98. package/dist/http-kit/index.d.ts +1 -0
  99. package/dist/http-kit/index.js +111 -0
  100. package/dist/http-kit/index.mjs +68 -0
  101. package/dist/http-kit/response.d.mts +19 -0
  102. package/dist/http-kit/response.d.ts +19 -0
  103. package/dist/http-kit/response.js +109 -0
  104. package/dist/http-kit/response.mjs +68 -0
  105. package/dist/index.d.mts +4 -0
  106. package/dist/index.d.ts +4 -0
  107. package/dist/index.js +91 -0
  108. package/dist/index.mjs +51 -0
  109. package/dist/route/api/auth/login/[provider]/route.js +113 -0
  110. package/dist/route/api/auth/login/[provider]/route.mjs +86 -0
  111. package/dist/route/api/auth/login/_provider_/route.d.mts +20 -0
  112. package/dist/route/api/auth/login/_provider_/route.d.ts +20 -0
  113. package/dist/route/api/auth/login/route.d.mts +14 -0
  114. package/dist/route/api/auth/login/route.d.ts +14 -0
  115. package/dist/route/api/auth/login/route.js +107 -0
  116. package/dist/route/api/auth/login/route.mjs +80 -0
  117. package/dist/route/api/auth/logout/route.d.mts +14 -0
  118. package/dist/route/api/auth/logout/route.d.ts +14 -0
  119. package/dist/route/api/auth/logout/route.js +98 -0
  120. package/dist/route/api/auth/logout/route.mjs +71 -0
  121. package/dist/route/api/auth/refresh/route.d.mts +13 -0
  122. package/dist/route/api/auth/refresh/route.d.ts +13 -0
  123. package/dist/route/api/auth/refresh/route.js +92 -0
  124. package/dist/route/api/auth/refresh/route.mjs +65 -0
  125. package/dist/route/api/auth/route.d.mts +13 -0
  126. package/dist/route/api/auth/route.d.ts +13 -0
  127. package/dist/route/api/auth/route.js +82 -0
  128. package/dist/route/api/auth/route.mjs +55 -0
  129. package/dist/route/api/files/[fileId]/route.js +99 -0
  130. package/dist/route/api/files/[fileId]/route.mjs +72 -0
  131. package/dist/route/api/files/_fileId_/route.d.mts +17 -0
  132. package/dist/route/api/files/_fileId_/route.d.ts +17 -0
  133. package/dist/route/api/files/route.d.mts +16 -0
  134. package/dist/route/api/files/route.d.ts +16 -0
  135. package/dist/route/api/files/route.js +106 -0
  136. package/dist/route/api/files/route.mjs +79 -0
  137. package/dist/route/api.d.mts +29 -0
  138. package/dist/route/api.d.ts +29 -0
  139. package/dist/route/api.js +395 -0
  140. package/dist/route/api.mjs +368 -0
  141. package/dist/route/auth/callback/[provider]/route.js +120 -0
  142. package/dist/route/auth/callback/[provider]/route.mjs +93 -0
  143. package/dist/route/auth/callback/_provider_/route.d.mts +20 -0
  144. package/dist/route/auth/callback/_provider_/route.d.ts +20 -0
  145. package/dist/seo-kit/index.d.mts +6 -0
  146. package/dist/seo-kit/index.d.ts +6 -0
  147. package/dist/seo-kit/index.js +321 -0
  148. package/dist/seo-kit/index.mjs +282 -0
  149. package/dist/seo-kit/loader.d.mts +7 -0
  150. package/dist/seo-kit/loader.d.ts +7 -0
  151. package/dist/seo-kit/loader.js +43 -0
  152. package/dist/seo-kit/loader.mjs +18 -0
  153. package/dist/seo-kit/seo.d.mts +103 -0
  154. package/dist/{esm/seo-kit → seo-kit}/seo.d.ts +10 -6
  155. package/dist/seo-kit/seo.js +286 -0
  156. package/dist/seo-kit/seo.mjs +251 -0
  157. package/dist/seo-kit/seo_loader.d.mts +16 -0
  158. package/dist/seo-kit/seo_loader.d.ts +16 -0
  159. package/dist/seo-kit/seo_loader.js +68 -0
  160. package/dist/seo-kit/seo_loader.mjs +31 -0
  161. package/dist/singleton.d.mts +3 -0
  162. package/dist/singleton.d.ts +3 -0
  163. package/dist/singleton.js +37 -0
  164. package/dist/singleton.mjs +12 -0
  165. package/dist/slug.d.mts +3 -0
  166. package/dist/slug.d.ts +3 -0
  167. package/dist/slug.js +32 -0
  168. package/dist/slug.mjs +7 -0
  169. package/package.json +36 -34
  170. package/tsup.config.ts +9 -0
  171. package/dist/cjs/auth-kit/apple_auth.js +0 -61
  172. package/dist/cjs/auth-kit/auth_service.js +0 -204
  173. package/dist/cjs/auth-kit/client/google_login_button.js +0 -19
  174. package/dist/cjs/auth-kit/client/redirect_page.js +0 -18
  175. package/dist/cjs/auth-kit/google_auth.js +0 -69
  176. package/dist/cjs/auth-kit/jwt.js +0 -54
  177. package/dist/cjs/auth-kit/kakao_auth.js +0 -43
  178. package/dist/cjs/auth-kit/repository.js +0 -2
  179. package/dist/cjs/auth-kit/with_auth.js +0 -46
  180. package/dist/cjs/cn.js +0 -6
  181. package/dist/cjs/components/index.js +0 -18
  182. package/dist/cjs/components/modal/fullscreen_container.js +0 -49
  183. package/dist/cjs/components/modal/hooks.js +0 -76
  184. package/dist/cjs/components/modal/index.js +0 -19
  185. package/dist/cjs/components/modal/modal.js +0 -79
  186. package/dist/cjs/components/styles.js +0 -10
  187. package/dist/cjs/date.js +0 -31
  188. package/dist/cjs/file-kit/cdn.js +0 -9
  189. package/dist/cjs/file-kit/client/drop_file_input.js +0 -148
  190. package/dist/cjs/file-kit/client/file_uploader.js +0 -88
  191. package/dist/cjs/file-kit/file_service.js +0 -32
  192. package/dist/cjs/file-kit/object_storage.js +0 -51
  193. package/dist/cjs/file-kit/repository.js +0 -2
  194. package/dist/cjs/file-kit/responsive_image.js +0 -63
  195. package/dist/cjs/http-kit/index.js +0 -17
  196. package/dist/cjs/http-kit/response.js +0 -37
  197. package/dist/cjs/index.js +0 -20
  198. package/dist/cjs/route/api/auth/login/[provider]/route.js +0 -36
  199. package/dist/cjs/route/api/auth/login/route.js +0 -35
  200. package/dist/cjs/route/api/auth/logout/route.js +0 -22
  201. package/dist/cjs/route/api/auth/refresh/route.js +0 -22
  202. package/dist/cjs/route/api/auth/route.js +0 -12
  203. package/dist/cjs/route/api/files/[fileId]/route.js +0 -20
  204. package/dist/cjs/route/api/files/route.js +0 -34
  205. package/dist/cjs/route/auth/callback/[provider]/route.js +0 -38
  206. package/dist/cjs/route/index.js +0 -80
  207. package/dist/cjs/seo-kit/index.js +0 -19
  208. package/dist/cjs/seo-kit/loader.js +0 -17
  209. package/dist/cjs/seo-kit/seo.js +0 -278
  210. package/dist/cjs/seo-kit/seo_loader.js +0 -15
  211. package/dist/cjs/singleton.js +0 -12
  212. package/dist/cjs/slug.js +0 -10
  213. package/dist/esm/auth-kit/apple_auth.js +0 -57
  214. package/dist/esm/auth-kit/auth_service.js +0 -197
  215. package/dist/esm/auth-kit/client/google_login_button.d.ts +0 -5
  216. package/dist/esm/auth-kit/client/google_login_button.js +0 -16
  217. package/dist/esm/auth-kit/client/redirect_page.d.ts +0 -1
  218. package/dist/esm/auth-kit/client/redirect_page.js +0 -15
  219. package/dist/esm/auth-kit/google_auth.js +0 -65
  220. package/dist/esm/auth-kit/jwt.js +0 -50
  221. package/dist/esm/auth-kit/kakao_auth.js +0 -39
  222. package/dist/esm/auth-kit/repository.js +0 -1
  223. package/dist/esm/auth-kit/with_auth.d.ts +0 -12
  224. package/dist/esm/auth-kit/with_auth.js +0 -43
  225. package/dist/esm/cn.d.ts +0 -1
  226. package/dist/esm/cn.js +0 -3
  227. package/dist/esm/components/index.d.ts +0 -2
  228. package/dist/esm/components/index.js +0 -2
  229. package/dist/esm/components/modal/fullscreen_container.d.ts +0 -5
  230. package/dist/esm/components/modal/fullscreen_container.js +0 -45
  231. package/dist/esm/components/modal/hooks.d.ts +0 -15
  232. package/dist/esm/components/modal/hooks.js +0 -67
  233. package/dist/esm/components/modal/index.d.ts +0 -3
  234. package/dist/esm/components/modal/index.js +0 -3
  235. package/dist/esm/components/modal/modal.d.ts +0 -10
  236. package/dist/esm/components/modal/modal.js +0 -43
  237. package/dist/esm/components/styles.d.ts +0 -7
  238. package/dist/esm/components/styles.js +0 -7
  239. package/dist/esm/date.d.ts +0 -1
  240. package/dist/esm/date.js +0 -24
  241. package/dist/esm/file-kit/cdn.d.ts +0 -3
  242. package/dist/esm/file-kit/cdn.js +0 -5
  243. package/dist/esm/file-kit/client/drop_file_input.js +0 -144
  244. package/dist/esm/file-kit/client/file_uploader.js +0 -84
  245. package/dist/esm/file-kit/file_service.js +0 -28
  246. package/dist/esm/file-kit/object_storage.js +0 -47
  247. package/dist/esm/file-kit/repository.js +0 -1
  248. package/dist/esm/file-kit/responsive_image.d.ts +0 -17
  249. package/dist/esm/file-kit/responsive_image.js +0 -58
  250. package/dist/esm/http-kit/index.d.ts +0 -1
  251. package/dist/esm/http-kit/index.js +0 -1
  252. package/dist/esm/http-kit/response.d.ts +0 -17
  253. package/dist/esm/http-kit/response.js +0 -31
  254. package/dist/esm/index.d.ts +0 -4
  255. package/dist/esm/index.js +0 -4
  256. package/dist/esm/route/api/auth/login/[provider]/route.d.ts +0 -10
  257. package/dist/esm/route/api/auth/login/[provider]/route.js +0 -32
  258. package/dist/esm/route/api/auth/login/route.d.ts +0 -6
  259. package/dist/esm/route/api/auth/login/route.js +0 -31
  260. package/dist/esm/route/api/auth/logout/route.d.ts +0 -6
  261. package/dist/esm/route/api/auth/logout/route.js +0 -18
  262. package/dist/esm/route/api/auth/refresh/route.d.ts +0 -4
  263. package/dist/esm/route/api/auth/refresh/route.js +0 -18
  264. package/dist/esm/route/api/auth/route.d.ts +0 -4
  265. package/dist/esm/route/api/auth/route.js +0 -8
  266. package/dist/esm/route/api/files/[fileId]/route.d.ts +0 -8
  267. package/dist/esm/route/api/files/[fileId]/route.js +0 -16
  268. package/dist/esm/route/api/files/route.d.ts +0 -6
  269. package/dist/esm/route/api/files/route.js +0 -30
  270. package/dist/esm/route/auth/callback/[provider]/route.d.ts +0 -11
  271. package/dist/esm/route/auth/callback/[provider]/route.js +0 -34
  272. package/dist/esm/route/index.d.ts +0 -22
  273. package/dist/esm/route/index.js +0 -76
  274. package/dist/esm/seo-kit/index.d.ts +0 -3
  275. package/dist/esm/seo-kit/index.js +0 -3
  276. package/dist/esm/seo-kit/loader.d.ts +0 -5
  277. package/dist/esm/seo-kit/loader.js +0 -14
  278. package/dist/esm/seo-kit/seo.js +0 -275
  279. package/dist/esm/seo-kit/seo_loader.d.ts +0 -12
  280. package/dist/esm/seo-kit/seo_loader.js +0 -12
  281. package/dist/esm/singleton.d.ts +0 -1
  282. package/dist/esm/singleton.js +0 -9
  283. package/dist/esm/slug.d.ts +0 -1
  284. package/dist/esm/slug.js +0 -6
@@ -1,197 +0,0 @@
1
- import bcryptjs from "bcryptjs";
2
- import { v4 } from "uuid";
3
- import { createCookie } from "react-router";
4
- export const ACCESS_TOKEN_KEY = "access_token";
5
- export const REFRESH_TOKEN_KEY = "refresh_token";
6
- export const 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
- export const 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
- export class AuthService {
19
- repository;
20
- JWT_MANAGER;
21
- OBJECT_STORAGE;
22
- constructor({ repository, JWT_MANAGER, OBJECT_STORAGE, }) {
23
- this.repository = repository;
24
- this.JWT_MANAGER = JWT_MANAGER;
25
- this.OBJECT_STORAGE = OBJECT_STORAGE;
26
- }
27
- async verify(request) {
28
- const accessToken = request?.headers.get("Authorization")?.replace("Bearer ", "") ||
29
- (await this.getAccessTokenFromCookies(request));
30
- if (accessToken) {
31
- return this.JWT_MANAGER.verifyAccessToken(accessToken);
32
- }
33
- }
34
- async verifyOrRefresh(request) {
35
- const payload = await this.verify(request);
36
- if (payload) {
37
- return payload;
38
- }
39
- return this.refresh(request);
40
- }
41
- async getAccessTokenFromCookies(request) {
42
- const cookieStore = await ACCESS_TOKEN_COOKIE.parse(request.headers.get("cookie"));
43
- return cookieStore.get(ACCESS_TOKEN_KEY)?.value;
44
- }
45
- async getRefreshTokenFromCookies(request) {
46
- const cookieStore = await REFRESH_TOKEN_COOKIE.parse(request.headers.get("cookie"));
47
- return cookieStore.get(REFRESH_TOKEN_KEY)?.value;
48
- }
49
- async refresh(request) {
50
- const refreshToken = await this.getRefreshTokenFromCookies(request);
51
- if (refreshToken) {
52
- try {
53
- const refreshedAccessToken = await this.refreshAccessToken(refreshToken);
54
- await this.getAccessTokenSetCookie(refreshedAccessToken);
55
- const payload = this.JWT_MANAGER.decode(refreshedAccessToken);
56
- if (payload) {
57
- return payload;
58
- }
59
- }
60
- catch (e) {
61
- if (e instanceof Error) {
62
- console.log(e.message);
63
- }
64
- return;
65
- }
66
- }
67
- }
68
- async signIn({ id, password }) {
69
- const credential = await this.repository.findCredentialById(id);
70
- if (!credential) {
71
- throw Error("아이디 또는 비밀번호가 틀렸습니다.");
72
- }
73
- if (!(await bcryptjs.compare(password, credential.password))) {
74
- throw Error("아이디 또는 비밀번호가 틀렸습니다.");
75
- }
76
- const user = await this.repository.findUserById(credential.userId);
77
- if (!user) {
78
- throw Error("회원 정보를 찾을 수 없습니다.");
79
- }
80
- const { accessToken, refreshToken } = await this.issueTokenPair(user);
81
- return {
82
- accessToken,
83
- refreshToken,
84
- };
85
- }
86
- async issueAccessToken(user) {
87
- return this.JWT_MANAGER.signAccessToken({
88
- userId: user.id,
89
- role: user.role,
90
- name: user.name,
91
- });
92
- }
93
- async issueTokenPair(user) {
94
- const refreshToken = await this.JWT_MANAGER.signRefreshToken({
95
- userId: user.id,
96
- role: user.role,
97
- name: user.name,
98
- });
99
- await this.repository.updateUserRefreshToken(user.id, await bcryptjs.hash(refreshToken, 10));
100
- const accessToken = await this.issueAccessToken(user);
101
- return { refreshToken, accessToken };
102
- }
103
- async refreshAccessToken(refreshToken) {
104
- const payload = await this.JWT_MANAGER.verifyRefreshToken(refreshToken);
105
- if (!payload) {
106
- throw new Error("토큰이 유효하지 않습니다.");
107
- }
108
- const { userId } = payload;
109
- if (typeof userId !== "string") {
110
- throw new Error("토큰이 유효하지 않습니다.");
111
- }
112
- const user = await this.repository.findUserById(userId);
113
- if (!user) {
114
- throw Error("이용자를 찾지 못했습니다.");
115
- }
116
- if (!user.refreshToken) {
117
- throw Error("인증 정보를 찾지 못했습니다.");
118
- }
119
- if (await bcryptjs.compare(user.refreshToken, refreshToken)) {
120
- throw Error("토큰이 유효하지 않습니다.");
121
- }
122
- const accessToken = await this.issueAccessToken(user);
123
- return accessToken;
124
- }
125
- async getAccessTokenSetCookie(accessToken) {
126
- return ACCESS_TOKEN_COOKIE.serialize(accessToken, {
127
- expires: accessToken
128
- ? this.JWT_MANAGER.getExpirationTime(accessToken)
129
- : new Date(0),
130
- });
131
- }
132
- async getRefreshTokenSetCookie(refreshToken) {
133
- return REFRESH_TOKEN_COOKIE.serialize(refreshToken, {
134
- expires: refreshToken
135
- ? this.JWT_MANAGER.getExpirationTime(refreshToken)
136
- : new Date(0),
137
- });
138
- }
139
- async findUser(provider, info) {
140
- const thirdPartyAuth = await this.repository.findThirdPartyAuth(provider, info.id);
141
- if (thirdPartyAuth) {
142
- const user = await this.repository.findUserById(thirdPartyAuth.userId);
143
- if (user) {
144
- return user;
145
- }
146
- }
147
- }
148
- async getOrCreateUser(provider, info) {
149
- const thirdPartyAuth = await this.repository.findThirdPartyAuth(provider, info.id);
150
- if (thirdPartyAuth) {
151
- const user = await this.repository.findUserById(thirdPartyAuth.userId);
152
- if (user) {
153
- return user;
154
- }
155
- }
156
- const userId = v4();
157
- const email = info.email;
158
- const name = info.name || "익명";
159
- const picture = info.picture;
160
- const profileImageId = (await this.savePicture(picture)) || null;
161
- const result = await this.repository.createUser({
162
- id: userId,
163
- role: "user",
164
- profileImageId,
165
- name,
166
- email,
167
- });
168
- await this.repository.createThirdPartyAuth({
169
- id: info.id,
170
- provider,
171
- userId,
172
- });
173
- return result;
174
- }
175
- async savePicture(picture) {
176
- if (!picture) {
177
- return;
178
- }
179
- const res = await fetch(picture);
180
- if (!res.ok) {
181
- return;
182
- }
183
- const buffer = await res.arrayBuffer();
184
- const id = v4();
185
- const key = `/users/${id}/picture`;
186
- await this.OBJECT_STORAGE.put(key, Buffer.from(buffer));
187
- await this.repository.createFile({
188
- id,
189
- name: "picture",
190
- type: "image/*",
191
- key,
192
- size: buffer.byteLength,
193
- metadata: {},
194
- });
195
- return id;
196
- }
197
- }
@@ -1,5 +0,0 @@
1
- export declare function GoogleLoginButton({ className, GOOGLE_CLIENT_ID, GOOGLE_REDIRECT_URI, }: {
2
- className?: string;
3
- GOOGLE_CLIENT_ID: string;
4
- GOOGLE_REDIRECT_URI: string;
5
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,16 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { FcGoogle } from "react-icons/fc";
3
- import { useSearchParams } from "react-router";
4
- export function GoogleLoginButton({ className = "max-w-[300px] w-full", GOOGLE_CLIENT_ID, GOOGLE_REDIRECT_URI, }) {
5
- const [searchParams] = useSearchParams();
6
- const redirectUrl = searchParams.get("redirectUrl") || "";
7
- const googleClientId = GOOGLE_CLIENT_ID || "";
8
- const googleRedirectUrl = GOOGLE_REDIRECT_URI || "";
9
- const href = new URL("https://accounts.google.com/o/oauth2/v2/auth");
10
- href.searchParams.append("client_id", googleClientId);
11
- href.searchParams.append("redirect_uri", googleRedirectUrl);
12
- href.searchParams.append("response_type", "code");
13
- href.searchParams.append("scope", "email profile");
14
- href.searchParams.append("state", redirectUrl);
15
- return (_jsx("div", { className: className, children: _jsxs("a", { href: href.toString(), 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", children: [_jsx(FcGoogle, {}), _jsx("p", { className: "text-[14px] text-black absolute left-0 right-0 text-center", children: "\uAD6C\uAE00\uB85C \uACC4\uC18D\uD558\uAE30" })] }) }));
16
- }
@@ -1 +0,0 @@
1
- export declare function RedirectPage(): import("react/jsx-runtime").JSX.Element;
@@ -1,15 +0,0 @@
1
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect } from "react";
3
- import { useNavigate } from "react-router";
4
- export function RedirectPage() {
5
- const navigate = useNavigate();
6
- useEffect(() => {
7
- const searchParams = new URLSearchParams(window.location.search);
8
- const redirectUrl = searchParams.get("redirectUrl") ||
9
- new URL("/", window.location.origin).toString();
10
- if (redirectUrl) {
11
- navigate(redirectUrl);
12
- }
13
- }, [navigate]);
14
- return _jsx(_Fragment, {});
15
- }
@@ -1,65 +0,0 @@
1
- import { BAD_REQUEST, createJsonResponse, INTERNAL_SERVER_ERROR, } from "../http-kit/response";
2
- export class GoogleAuth {
3
- AUTH;
4
- GOOGLE_CLIENT_ID;
5
- GOOGLE_CLIENT_SECRET;
6
- GOOGLE_REDIRECT_URI;
7
- constructor(AUTH, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_REDIRECT_URI) {
8
- this.GOOGLE_CLIENT_ID = GOOGLE_CLIENT_ID;
9
- this.GOOGLE_CLIENT_SECRET = GOOGLE_CLIENT_SECRET;
10
- this.GOOGLE_REDIRECT_URI = GOOGLE_REDIRECT_URI;
11
- this.AUTH = AUTH;
12
- }
13
- async signIn(code) {
14
- const tokenRes = await fetch("https://oauth2.googleapis.com/token", {
15
- method: "POST",
16
- headers: {
17
- "Content-Type": "application/x-www-form-urlencoded",
18
- },
19
- body: new URLSearchParams({
20
- code,
21
- client_id: this.GOOGLE_CLIENT_ID,
22
- client_secret: this.GOOGLE_CLIENT_SECRET,
23
- redirect_uri: this.GOOGLE_REDIRECT_URI,
24
- grant_type: "authorization_code",
25
- }),
26
- });
27
- if (!tokenRes.ok) {
28
- if (process.env.NODE_ENV === "development") {
29
- throw INTERNAL_SERVER_ERROR(`구글 토큰 발급에 실패했습니다. status: ${tokenRes.status}, message: ${await tokenRes.text()}`);
30
- }
31
- throw INTERNAL_SERVER_ERROR("인증에 실패했습니다.");
32
- }
33
- const { access_token } = await tokenRes.json();
34
- const userRes = await fetch("https://www.googleapis.com/oauth2/v1/userinfo", {
35
- headers: {
36
- Authorization: `Bearer ${access_token}`,
37
- },
38
- });
39
- if (!userRes.ok) {
40
- throw BAD_REQUEST("유저 정보를 가져오는데 실패했습니다.");
41
- }
42
- const { id, email, name, picture } = await userRes.json();
43
- const user = await this.AUTH.findUser("google", {
44
- id,
45
- email,
46
- name,
47
- picture,
48
- });
49
- if (!user) {
50
- throw createJsonResponse(404)({
51
- provider: "google",
52
- id,
53
- name,
54
- picture,
55
- message: "사용자를 찾을 수 없습니다.",
56
- });
57
- }
58
- const { accessToken, refreshToken } = await this.AUTH.issueTokenPair(user);
59
- return {
60
- user,
61
- accessToken,
62
- refreshToken,
63
- };
64
- }
65
- }
@@ -1,50 +0,0 @@
1
- import { SignJWT, decodeJwt, jwtVerify } from "jose";
2
- export class JWTManager {
3
- siteOrigin;
4
- constructor(siteOrigin) {
5
- this.siteOrigin = siteOrigin;
6
- }
7
- async verify(token, secret) {
8
- try {
9
- const result = await jwtVerify(token, new TextEncoder().encode(secret));
10
- return result.payload;
11
- }
12
- catch (_) {
13
- return;
14
- }
15
- }
16
- async verifyAccessToken(token) {
17
- return this.verify(token, process.env.ACCESS_TOKEN_SECRET);
18
- }
19
- async verifyRefreshToken(token) {
20
- return this.verify(token, process.env.REFRESH_TOKEN_SECRET);
21
- }
22
- async sign(payload, secret, { expiresIn } = {}) {
23
- let builder = new SignJWT(payload)
24
- .setProtectedHeader({ alg: "HS256", typ: "JWT" })
25
- .setIssuedAt();
26
- if (this.siteOrigin) {
27
- builder = builder.setIssuer(this.siteOrigin);
28
- }
29
- if (expiresIn) {
30
- builder = builder.setExpirationTime(expiresIn);
31
- }
32
- return builder.sign(new TextEncoder().encode(secret));
33
- }
34
- async signAccessToken(payload) {
35
- return this.sign(payload, process.env.ACCESS_TOKEN_SECRET, {
36
- expiresIn: process.env.ACCESS_TOKEN_EXPIRES_IN || "10s",
37
- });
38
- }
39
- async signRefreshToken(payload) {
40
- return this.sign(payload, process.env.REFRESH_TOKEN_SECRET, {
41
- expiresIn: process.env.REFRESH_TOKEN_EXPIRES_IN || "1d",
42
- });
43
- }
44
- decode(token) {
45
- return decodeJwt(token);
46
- }
47
- getExpirationTime(token) {
48
- return new Date(Number(decodeJwt(token).exp) * 1000);
49
- }
50
- }
@@ -1,39 +0,0 @@
1
- import { createJsonResponse } from "../http-kit";
2
- export class KakaoAuth {
3
- AUTH;
4
- constructor(AUTH) {
5
- this.AUTH = AUTH;
6
- }
7
- async signIn(kakaoAccessToken) {
8
- const userRes = await fetch("https://kapi.kakao.com/v2/user/me", {
9
- headers: {
10
- Authorization: `Bearer ${kakaoAccessToken}`,
11
- },
12
- });
13
- if (!userRes.ok) {
14
- throw new Error("유저 정보를 가져오는데 실패했습니다.");
15
- }
16
- const { id, kakao_account } = await userRes.json();
17
- const { email, profile } = kakao_account;
18
- const payload = {
19
- id,
20
- email,
21
- name: profile.nickname,
22
- picture: profile.thumbnail_image_url,
23
- };
24
- const user = await this.AUTH.findUser("kakao", payload);
25
- if (!user) {
26
- throw createJsonResponse(404)({
27
- provider: "kakao",
28
- ...payload,
29
- message: "사용자를 찾을 수 없습니다.",
30
- });
31
- }
32
- const { accessToken, refreshToken } = await this.AUTH.issueTokenPair(user);
33
- return {
34
- user,
35
- accessToken,
36
- refreshToken,
37
- };
38
- }
39
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
2
- import { AuthService } from "./auth_service";
3
- import { JWTManager } from "./jwt";
4
- import type { JWTPayload } from "jose";
5
- type Fn<T extends LoaderFunctionArgs | ActionFunctionArgs> = (arg: T) => Promise<unknown> | unknown;
6
- type InputFN = (auth?: JWTPayload) => Fn<LoaderFunctionArgs> | Fn<ActionFunctionArgs>;
7
- export type WithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (fn: InputFN) => Fn<T>;
8
- export declare function createWithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs>({ JWT_MANAGER, AUTH, }: {
9
- JWT_MANAGER: JWTManager;
10
- AUTH: AuthService;
11
- }): WithAuthHandler<T>;
12
- export {};
@@ -1,43 +0,0 @@
1
- import { ACCESS_TOKEN_COOKIE, REFRESH_TOKEN_COOKIE, } from "./auth_service";
2
- export function createWithAuthHandler({ JWT_MANAGER, AUTH, }) {
3
- return function (fn) {
4
- return async function (arg) {
5
- const cookie = arg.request.headers.get("cookie");
6
- const accessToken = await ACCESS_TOKEN_COOKIE.parse(cookie);
7
- if (accessToken) {
8
- const payload = await JWT_MANAGER.verifyAccessToken(accessToken);
9
- if (payload) {
10
- return fn(payload)(arg);
11
- }
12
- }
13
- const refreshToken = await REFRESH_TOKEN_COOKIE.parse(cookie);
14
- if (refreshToken) {
15
- try {
16
- const refreshedAccessToken = await AUTH.refreshAccessToken(refreshToken);
17
- const setCookieHeader = await AUTH.getRefreshTokenSetCookie(refreshedAccessToken);
18
- return new Response("Temporary Redirect", {
19
- status: 307,
20
- headers: {
21
- "Set-Cookie": setCookieHeader,
22
- Location: arg.request.url,
23
- },
24
- });
25
- }
26
- catch (e) {
27
- if (e instanceof Error) {
28
- console.log(e.message);
29
- }
30
- const setCookieHeader = await AUTH.getRefreshTokenSetCookie(null);
31
- return new Response("Temporary Redirect", {
32
- status: 307,
33
- headers: {
34
- "Set-Cookie": setCookieHeader,
35
- Location: arg.request.url,
36
- },
37
- });
38
- }
39
- }
40
- return fn(undefined)(arg);
41
- };
42
- };
43
- }
package/dist/esm/cn.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function cn(...classes: (string | false | undefined)[]): string;
package/dist/esm/cn.js DELETED
@@ -1,3 +0,0 @@
1
- export function cn(...classes) {
2
- return classes.filter(Boolean).join(" ").trim();
3
- }
@@ -1,2 +0,0 @@
1
- export * from "./modal";
2
- export * from "./styles";
@@ -1,2 +0,0 @@
1
- export * from "./modal";
2
- export * from "./styles";
@@ -1,5 +0,0 @@
1
- import React from "react";
2
- import { type DetailedHTMLProps, type HTMLAttributes } from "react";
3
- export type Props = DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
4
- export default function FullscreenContainer({ className, children, ...props }: Props): import("react/jsx-runtime").JSX.Element;
5
- export declare function useFullscreen(ref: React.RefObject<HTMLDivElement | null>): string;
@@ -1,45 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { cn } from "../../cn";
3
- import { useEffect, useRef, } from "react";
4
- export default function FullscreenContainer({ className, children, ...props }) {
5
- const containerRef = useRef(null);
6
- useFullscreen(containerRef);
7
- return (_jsx("div", { ref: containerRef, ...props, className: cn("fixed left-0 right-0 top-0 bottom-0", className), children: children }));
8
- }
9
- export function useFullscreen(ref) {
10
- useEffect(() => {
11
- const container = ref.current;
12
- if (!container) {
13
- return;
14
- }
15
- const scroll = () => {
16
- if (scrollY > 0) {
17
- window.scrollTo({
18
- top: 0,
19
- behavior: "instant",
20
- });
21
- }
22
- };
23
- const resize = () => {
24
- if (!visualViewport) {
25
- return;
26
- }
27
- container.classList.remove("bottom-0");
28
- container.style.height = `${visualViewport?.height}px`;
29
- if (visualViewport.height < window.innerHeight) {
30
- window.addEventListener("scroll", scroll);
31
- }
32
- else {
33
- window.removeEventListener("scroll", scroll);
34
- }
35
- };
36
- resize();
37
- visualViewport?.addEventListener("resize", resize);
38
- scroll();
39
- return () => {
40
- window.removeEventListener("scroll", scroll);
41
- visualViewport?.removeEventListener("resize", resize);
42
- };
43
- }, [ref]);
44
- return "fixed inset-0";
45
- }
@@ -1,15 +0,0 @@
1
- import { type ModalProps } from "./modal";
2
- import React from "react";
3
- export declare function useModalRoot(): HTMLElement | null;
4
- export declare function useModalPortal(): ((children: React.ReactNode) => null) | ((children: React.ReactNode) => React.ReactPortal);
5
- export type ModalContextProps = {
6
- open: () => void;
7
- close: () => void;
8
- isOpen: boolean;
9
- };
10
- export declare const ModalContext: React.Context<ModalContextProps>;
11
- export declare function useModal(): {
12
- open: () => void;
13
- close: () => void;
14
- Modal: (props: Omit<ModalProps, "open">) => import("react/jsx-runtime").JSX.Element;
15
- };
@@ -1,67 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useCallback, useEffect, useRef, useState } from "react";
3
- import { createPortal } from "react-dom";
4
- import Modal from "./modal";
5
- export function useModalRoot() {
6
- const [container, setContainer] = useState(null);
7
- useEffect(() => {
8
- const container = document.getElementById("modal-root");
9
- if (container) {
10
- setContainer(container);
11
- }
12
- return () => {
13
- setContainer(null);
14
- };
15
- }, []);
16
- return container;
17
- }
18
- export function useModalPortal() {
19
- const container = useModalRoot();
20
- if (!container) {
21
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
- return (children) => null;
23
- }
24
- return (children) => {
25
- return createPortal(children, container);
26
- };
27
- }
28
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
- export const ModalContext = createContext({});
30
- export function useModal() {
31
- const ch2 = useRef(null);
32
- const open = () => {
33
- ch2.current?.(true);
34
- };
35
- const close = () => {
36
- ch2.current?.(false);
37
- };
38
- const Component = useCallback(function Component(props) {
39
- const [isOpen, setIsOpen] = useState(false);
40
- const createPortal = useModalPortal();
41
- useEffect(() => {
42
- ch2.current = (v) => {
43
- setIsOpen(v);
44
- };
45
- return () => {
46
- ch2.current = null;
47
- };
48
- }, []);
49
- useEffect(() => {
50
- if (isOpen) {
51
- // document.body.style.overflow = "hidden";
52
- }
53
- else {
54
- // document.body.style.overflow = "";
55
- }
56
- return () => {
57
- // document.body.style.overflow = "";
58
- };
59
- }, [isOpen]);
60
- return (_jsx(ModalContext.Provider, { value: { open, close, isOpen }, children: createPortal(_jsx(Modal, { ...props, open: isOpen, onBackgroundClick: close })) }));
61
- }, []);
62
- return {
63
- open,
64
- close,
65
- Modal: Component,
66
- };
67
- }
@@ -1,3 +0,0 @@
1
- export * from "./fullscreen_container";
2
- export * from "./hooks";
3
- export * from "./modal";
@@ -1,3 +0,0 @@
1
- export * from "./fullscreen_container";
2
- export * from "./hooks";
3
- export * from "./modal";
@@ -1,10 +0,0 @@
1
- import React, { type ReactNode } from "react";
2
- export type ModalProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
3
- open: boolean;
4
- children?: ReactNode;
5
- onBackgroundClick?: () => void;
6
- embeded?: boolean;
7
- always?: boolean;
8
- background?: string;
9
- };
10
- export default function Modal({ open, className, background, onBackgroundClick, children, ...props }: ModalProps): import("react/jsx-runtime").JSX.Element;