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.
- package/dist/auth-kit/apple_auth.d.mts +24 -0
- package/dist/{esm/auth-kit → auth-kit}/apple_auth.d.ts +11 -2
- package/dist/auth-kit/apple_auth.js +75 -0
- package/dist/auth-kit/apple_auth.mjs +50 -0
- package/dist/auth-kit/auth_service.d.mts +73 -0
- package/dist/{esm/auth-kit → auth-kit}/auth_service.d.ts +17 -11
- package/dist/auth-kit/auth_service.js +257 -0
- package/dist/auth-kit/auth_service.mjs +218 -0
- package/dist/auth-kit/client/google_login_button.d.mts +9 -0
- package/dist/auth-kit/client/google_login_button.d.ts +9 -0
- package/dist/auth-kit/client/google_login_button.js +67 -0
- package/dist/auth-kit/client/google_login_button.mjs +32 -0
- package/dist/auth-kit/client/redirect_page.d.mts +5 -0
- package/dist/auth-kit/client/redirect_page.d.ts +5 -0
- package/dist/auth-kit/client/redirect_page.js +53 -0
- package/dist/auth-kit/client/redirect_page.mjs +18 -0
- package/dist/auth-kit/google_auth.d.mts +27 -0
- package/dist/{esm/auth-kit → auth-kit}/google_auth.d.ts +11 -2
- package/dist/auth-kit/google_auth.js +144 -0
- package/dist/auth-kit/google_auth.mjs +117 -0
- package/dist/auth-kit/jwt.d.mts +18 -0
- package/dist/{esm/auth-kit → auth-kit}/jwt.d.ts +5 -2
- package/dist/auth-kit/jwt.js +76 -0
- package/dist/auth-kit/jwt.mjs +51 -0
- package/dist/auth-kit/kakao_auth.d.mts +24 -0
- package/dist/{esm/auth-kit → auth-kit}/kakao_auth.d.ts +11 -2
- package/dist/auth-kit/kakao_auth.js +115 -0
- package/dist/auth-kit/kakao_auth.mjs +88 -0
- package/dist/auth-kit/repository.d.mts +42 -0
- package/dist/{esm/auth-kit → auth-kit}/repository.d.ts +3 -1
- package/dist/auth-kit/repository.js +18 -0
- package/dist/auth-kit/repository.mjs +0 -0
- package/dist/auth-kit/with_auth.d.mts +17 -0
- package/dist/auth-kit/with_auth.d.ts +17 -0
- package/dist/auth-kit/with_auth.js +106 -0
- package/dist/auth-kit/with_auth.mjs +69 -0
- package/dist/cn.d.mts +3 -0
- package/dist/cn.d.ts +3 -0
- package/dist/cn.js +32 -0
- package/dist/cn.mjs +7 -0
- package/dist/components/index.d.mts +5 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +261 -0
- package/dist/components/index.mjs +219 -0
- package/dist/components/modal/fullscreen_container.d.mts +7 -0
- package/dist/components/modal/fullscreen_container.d.ts +7 -0
- package/dist/components/modal/fullscreen_container.js +102 -0
- package/dist/components/modal/fullscreen_container.mjs +68 -0
- package/dist/components/modal/hooks.d.mts +18 -0
- package/dist/components/modal/hooks.d.ts +18 -0
- package/dist/components/modal/hooks.js +236 -0
- package/dist/components/modal/hooks.mjs +204 -0
- package/dist/components/modal/index.d.mts +4 -0
- package/dist/components/modal/index.d.ts +4 -0
- package/dist/components/modal/index.js +238 -0
- package/dist/components/modal/index.mjs +203 -0
- package/dist/components/modal/modal.d.mts +13 -0
- package/dist/components/modal/modal.d.ts +13 -0
- package/dist/components/modal/modal.js +155 -0
- package/dist/components/modal/modal.mjs +130 -0
- package/dist/components/styles.d.mts +9 -0
- package/dist/components/styles.d.ts +9 -0
- package/dist/components/styles.js +48 -0
- package/dist/components/styles.mjs +17 -0
- package/dist/date.d.mts +3 -0
- package/dist/date.d.ts +3 -0
- package/dist/date.js +63 -0
- package/dist/date.mjs +28 -0
- package/dist/file-kit/cdn.d.mts +5 -0
- package/dist/file-kit/cdn.d.ts +5 -0
- package/dist/file-kit/cdn.js +34 -0
- package/dist/file-kit/cdn.mjs +9 -0
- package/dist/file-kit/client/drop_file_input.d.mts +33 -0
- package/dist/{esm/file-kit → file-kit}/client/drop_file_input.d.ts +10 -8
- package/dist/file-kit/client/drop_file_input.js +235 -0
- package/dist/file-kit/client/drop_file_input.mjs +205 -0
- package/dist/file-kit/client/file_uploader.d.mts +13 -0
- package/dist/{esm/file-kit → file-kit}/client/file_uploader.d.ts +4 -2
- package/dist/file-kit/client/file_uploader.js +115 -0
- package/dist/file-kit/client/file_uploader.mjs +90 -0
- package/dist/file-kit/file_service.d.mts +26 -0
- package/dist/{esm/file-kit → file-kit}/file_service.d.ts +7 -4
- package/dist/file-kit/file_service.js +60 -0
- package/dist/file-kit/file_service.mjs +35 -0
- package/dist/file-kit/object_storage.d.mts +17 -0
- package/dist/{esm/file-kit → file-kit}/object_storage.d.ts +6 -2
- package/dist/file-kit/object_storage.js +78 -0
- package/dist/file-kit/object_storage.mjs +57 -0
- package/dist/file-kit/repository.d.mts +16 -0
- package/dist/{esm/file-kit → file-kit}/repository.d.ts +3 -1
- package/dist/file-kit/repository.js +18 -0
- package/dist/file-kit/repository.mjs +0 -0
- package/dist/file-kit/responsive_image.d.mts +20 -0
- package/dist/file-kit/responsive_image.d.ts +20 -0
- package/dist/file-kit/responsive_image.js +123 -0
- package/dist/file-kit/responsive_image.mjs +87 -0
- package/dist/http-kit/index.d.mts +1 -0
- package/dist/http-kit/index.d.ts +1 -0
- package/dist/http-kit/index.js +111 -0
- package/dist/http-kit/index.mjs +68 -0
- package/dist/http-kit/response.d.mts +19 -0
- package/dist/http-kit/response.d.ts +19 -0
- package/dist/http-kit/response.js +109 -0
- package/dist/http-kit/response.mjs +68 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +91 -0
- package/dist/index.mjs +51 -0
- package/dist/route/api/auth/login/[provider]/route.js +113 -0
- package/dist/route/api/auth/login/[provider]/route.mjs +86 -0
- package/dist/route/api/auth/login/_provider_/route.d.mts +20 -0
- package/dist/route/api/auth/login/_provider_/route.d.ts +20 -0
- package/dist/route/api/auth/login/route.d.mts +14 -0
- package/dist/route/api/auth/login/route.d.ts +14 -0
- package/dist/route/api/auth/login/route.js +107 -0
- package/dist/route/api/auth/login/route.mjs +80 -0
- package/dist/route/api/auth/logout/route.d.mts +14 -0
- package/dist/route/api/auth/logout/route.d.ts +14 -0
- package/dist/route/api/auth/logout/route.js +98 -0
- package/dist/route/api/auth/logout/route.mjs +71 -0
- package/dist/route/api/auth/refresh/route.d.mts +13 -0
- package/dist/route/api/auth/refresh/route.d.ts +13 -0
- package/dist/route/api/auth/refresh/route.js +92 -0
- package/dist/route/api/auth/refresh/route.mjs +65 -0
- package/dist/route/api/auth/route.d.mts +13 -0
- package/dist/route/api/auth/route.d.ts +13 -0
- package/dist/route/api/auth/route.js +82 -0
- package/dist/route/api/auth/route.mjs +55 -0
- package/dist/route/api/files/[fileId]/route.js +99 -0
- package/dist/route/api/files/[fileId]/route.mjs +72 -0
- package/dist/route/api/files/_fileId_/route.d.mts +17 -0
- package/dist/route/api/files/_fileId_/route.d.ts +17 -0
- package/dist/route/api/files/route.d.mts +16 -0
- package/dist/route/api/files/route.d.ts +16 -0
- package/dist/route/api/files/route.js +106 -0
- package/dist/route/api/files/route.mjs +79 -0
- package/dist/route/api.d.mts +29 -0
- package/dist/route/api.d.ts +29 -0
- package/dist/route/api.js +395 -0
- package/dist/route/api.mjs +368 -0
- package/dist/route/auth/callback/[provider]/route.js +120 -0
- package/dist/route/auth/callback/[provider]/route.mjs +93 -0
- package/dist/route/auth/callback/_provider_/route.d.mts +20 -0
- package/dist/route/auth/callback/_provider_/route.d.ts +20 -0
- package/dist/seo-kit/index.d.mts +6 -0
- package/dist/seo-kit/index.d.ts +6 -0
- package/dist/seo-kit/index.js +321 -0
- package/dist/seo-kit/index.mjs +282 -0
- package/dist/seo-kit/loader.d.mts +7 -0
- package/dist/seo-kit/loader.d.ts +7 -0
- package/dist/seo-kit/loader.js +43 -0
- package/dist/seo-kit/loader.mjs +18 -0
- package/dist/seo-kit/seo.d.mts +103 -0
- package/dist/{esm/seo-kit → seo-kit}/seo.d.ts +10 -6
- package/dist/seo-kit/seo.js +286 -0
- package/dist/seo-kit/seo.mjs +251 -0
- package/dist/seo-kit/seo_loader.d.mts +16 -0
- package/dist/seo-kit/seo_loader.d.ts +16 -0
- package/dist/seo-kit/seo_loader.js +68 -0
- package/dist/seo-kit/seo_loader.mjs +31 -0
- package/dist/singleton.d.mts +3 -0
- package/dist/singleton.d.ts +3 -0
- package/dist/singleton.js +37 -0
- package/dist/singleton.mjs +12 -0
- package/dist/slug.d.mts +3 -0
- package/dist/slug.d.ts +3 -0
- package/dist/slug.js +32 -0
- package/dist/slug.mjs +7 -0
- package/package.json +36 -34
- package/tsup.config.ts +9 -0
- package/dist/cjs/auth-kit/apple_auth.js +0 -61
- package/dist/cjs/auth-kit/auth_service.js +0 -204
- package/dist/cjs/auth-kit/client/google_login_button.js +0 -19
- package/dist/cjs/auth-kit/client/redirect_page.js +0 -18
- package/dist/cjs/auth-kit/google_auth.js +0 -69
- package/dist/cjs/auth-kit/jwt.js +0 -54
- package/dist/cjs/auth-kit/kakao_auth.js +0 -43
- package/dist/cjs/auth-kit/repository.js +0 -2
- package/dist/cjs/auth-kit/with_auth.js +0 -46
- package/dist/cjs/cn.js +0 -6
- package/dist/cjs/components/index.js +0 -18
- package/dist/cjs/components/modal/fullscreen_container.js +0 -49
- package/dist/cjs/components/modal/hooks.js +0 -76
- package/dist/cjs/components/modal/index.js +0 -19
- package/dist/cjs/components/modal/modal.js +0 -79
- package/dist/cjs/components/styles.js +0 -10
- package/dist/cjs/date.js +0 -31
- package/dist/cjs/file-kit/cdn.js +0 -9
- package/dist/cjs/file-kit/client/drop_file_input.js +0 -148
- package/dist/cjs/file-kit/client/file_uploader.js +0 -88
- package/dist/cjs/file-kit/file_service.js +0 -32
- package/dist/cjs/file-kit/object_storage.js +0 -51
- package/dist/cjs/file-kit/repository.js +0 -2
- package/dist/cjs/file-kit/responsive_image.js +0 -63
- package/dist/cjs/http-kit/index.js +0 -17
- package/dist/cjs/http-kit/response.js +0 -37
- package/dist/cjs/index.js +0 -20
- package/dist/cjs/route/api/auth/login/[provider]/route.js +0 -36
- package/dist/cjs/route/api/auth/login/route.js +0 -35
- package/dist/cjs/route/api/auth/logout/route.js +0 -22
- package/dist/cjs/route/api/auth/refresh/route.js +0 -22
- package/dist/cjs/route/api/auth/route.js +0 -12
- package/dist/cjs/route/api/files/[fileId]/route.js +0 -20
- package/dist/cjs/route/api/files/route.js +0 -34
- package/dist/cjs/route/auth/callback/[provider]/route.js +0 -38
- package/dist/cjs/route/index.js +0 -80
- package/dist/cjs/seo-kit/index.js +0 -19
- package/dist/cjs/seo-kit/loader.js +0 -17
- package/dist/cjs/seo-kit/seo.js +0 -278
- package/dist/cjs/seo-kit/seo_loader.js +0 -15
- package/dist/cjs/singleton.js +0 -12
- package/dist/cjs/slug.js +0 -10
- package/dist/esm/auth-kit/apple_auth.js +0 -57
- package/dist/esm/auth-kit/auth_service.js +0 -197
- package/dist/esm/auth-kit/client/google_login_button.d.ts +0 -5
- package/dist/esm/auth-kit/client/google_login_button.js +0 -16
- package/dist/esm/auth-kit/client/redirect_page.d.ts +0 -1
- package/dist/esm/auth-kit/client/redirect_page.js +0 -15
- package/dist/esm/auth-kit/google_auth.js +0 -65
- package/dist/esm/auth-kit/jwt.js +0 -50
- package/dist/esm/auth-kit/kakao_auth.js +0 -39
- package/dist/esm/auth-kit/repository.js +0 -1
- package/dist/esm/auth-kit/with_auth.d.ts +0 -12
- package/dist/esm/auth-kit/with_auth.js +0 -43
- package/dist/esm/cn.d.ts +0 -1
- package/dist/esm/cn.js +0 -3
- package/dist/esm/components/index.d.ts +0 -2
- package/dist/esm/components/index.js +0 -2
- package/dist/esm/components/modal/fullscreen_container.d.ts +0 -5
- package/dist/esm/components/modal/fullscreen_container.js +0 -45
- package/dist/esm/components/modal/hooks.d.ts +0 -15
- package/dist/esm/components/modal/hooks.js +0 -67
- package/dist/esm/components/modal/index.d.ts +0 -3
- package/dist/esm/components/modal/index.js +0 -3
- package/dist/esm/components/modal/modal.d.ts +0 -10
- package/dist/esm/components/modal/modal.js +0 -43
- package/dist/esm/components/styles.d.ts +0 -7
- package/dist/esm/components/styles.js +0 -7
- package/dist/esm/date.d.ts +0 -1
- package/dist/esm/date.js +0 -24
- package/dist/esm/file-kit/cdn.d.ts +0 -3
- package/dist/esm/file-kit/cdn.js +0 -5
- package/dist/esm/file-kit/client/drop_file_input.js +0 -144
- package/dist/esm/file-kit/client/file_uploader.js +0 -84
- package/dist/esm/file-kit/file_service.js +0 -28
- package/dist/esm/file-kit/object_storage.js +0 -47
- package/dist/esm/file-kit/repository.js +0 -1
- package/dist/esm/file-kit/responsive_image.d.ts +0 -17
- package/dist/esm/file-kit/responsive_image.js +0 -58
- package/dist/esm/http-kit/index.d.ts +0 -1
- package/dist/esm/http-kit/index.js +0 -1
- package/dist/esm/http-kit/response.d.ts +0 -17
- package/dist/esm/http-kit/response.js +0 -31
- package/dist/esm/index.d.ts +0 -4
- package/dist/esm/index.js +0 -4
- package/dist/esm/route/api/auth/login/[provider]/route.d.ts +0 -10
- package/dist/esm/route/api/auth/login/[provider]/route.js +0 -32
- package/dist/esm/route/api/auth/login/route.d.ts +0 -6
- package/dist/esm/route/api/auth/login/route.js +0 -31
- package/dist/esm/route/api/auth/logout/route.d.ts +0 -6
- package/dist/esm/route/api/auth/logout/route.js +0 -18
- package/dist/esm/route/api/auth/refresh/route.d.ts +0 -4
- package/dist/esm/route/api/auth/refresh/route.js +0 -18
- package/dist/esm/route/api/auth/route.d.ts +0 -4
- package/dist/esm/route/api/auth/route.js +0 -8
- package/dist/esm/route/api/files/[fileId]/route.d.ts +0 -8
- package/dist/esm/route/api/files/[fileId]/route.js +0 -16
- package/dist/esm/route/api/files/route.d.ts +0 -6
- package/dist/esm/route/api/files/route.js +0 -30
- package/dist/esm/route/auth/callback/[provider]/route.d.ts +0 -11
- package/dist/esm/route/auth/callback/[provider]/route.js +0 -34
- package/dist/esm/route/index.d.ts +0 -22
- package/dist/esm/route/index.js +0 -76
- package/dist/esm/seo-kit/index.d.ts +0 -3
- package/dist/esm/seo-kit/index.js +0 -3
- package/dist/esm/seo-kit/loader.d.ts +0 -5
- package/dist/esm/seo-kit/loader.js +0 -14
- package/dist/esm/seo-kit/seo.js +0 -275
- package/dist/esm/seo-kit/seo_loader.d.ts +0 -12
- package/dist/esm/seo-kit/seo_loader.js +0 -12
- package/dist/esm/singleton.d.ts +0 -1
- package/dist/esm/singleton.js +0 -9
- package/dist/esm/slug.d.ts +0 -1
- package/dist/esm/slug.js +0 -6
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// src/auth-kit/auth_service.ts
|
|
2
|
+
import bcryptjs from "bcryptjs";
|
|
3
|
+
import { v4 } from "uuid";
|
|
4
|
+
import { createCookie } from "react-router";
|
|
5
|
+
var ACCESS_TOKEN_KEY = "access_token";
|
|
6
|
+
var REFRESH_TOKEN_KEY = "refresh_token";
|
|
7
|
+
var ACCESS_TOKEN_COOKIE = createCookie(ACCESS_TOKEN_KEY, {
|
|
8
|
+
path: "/",
|
|
9
|
+
httpOnly: process.env.NODE_ENV === "production",
|
|
10
|
+
secure: process.env.NODE_ENV === "production",
|
|
11
|
+
sameSite: "strict"
|
|
12
|
+
});
|
|
13
|
+
var REFRESH_TOKEN_COOKIE = createCookie(REFRESH_TOKEN_KEY, {
|
|
14
|
+
path: "/",
|
|
15
|
+
httpOnly: process.env.NODE_ENV === "production",
|
|
16
|
+
secure: process.env.NODE_ENV === "production",
|
|
17
|
+
sameSite: "strict"
|
|
18
|
+
});
|
|
19
|
+
var AuthService = class {
|
|
20
|
+
repository;
|
|
21
|
+
JWT_MANAGER;
|
|
22
|
+
OBJECT_STORAGE;
|
|
23
|
+
constructor({
|
|
24
|
+
repository,
|
|
25
|
+
JWT_MANAGER,
|
|
26
|
+
OBJECT_STORAGE
|
|
27
|
+
}) {
|
|
28
|
+
this.repository = repository;
|
|
29
|
+
this.JWT_MANAGER = JWT_MANAGER;
|
|
30
|
+
this.OBJECT_STORAGE = OBJECT_STORAGE;
|
|
31
|
+
}
|
|
32
|
+
async verify(request) {
|
|
33
|
+
const accessToken = request?.headers.get("Authorization")?.replace("Bearer ", "") || await this.getAccessTokenFromCookies(request);
|
|
34
|
+
if (accessToken) {
|
|
35
|
+
return this.JWT_MANAGER.verifyAccessToken(accessToken);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async verifyOrRefresh(request) {
|
|
39
|
+
const payload = await this.verify(request);
|
|
40
|
+
if (payload) {
|
|
41
|
+
return payload;
|
|
42
|
+
}
|
|
43
|
+
return this.refresh(request);
|
|
44
|
+
}
|
|
45
|
+
async getAccessTokenFromCookies(request) {
|
|
46
|
+
const accessToken = await ACCESS_TOKEN_COOKIE.parse(
|
|
47
|
+
request.headers.get("cookie")
|
|
48
|
+
);
|
|
49
|
+
return accessToken;
|
|
50
|
+
}
|
|
51
|
+
async getRefreshTokenFromCookies(request) {
|
|
52
|
+
const refreshToken = await REFRESH_TOKEN_COOKIE.parse(
|
|
53
|
+
request.headers.get("cookie")
|
|
54
|
+
);
|
|
55
|
+
return refreshToken;
|
|
56
|
+
}
|
|
57
|
+
async refresh(request) {
|
|
58
|
+
const refreshToken = await this.getRefreshTokenFromCookies(request);
|
|
59
|
+
if (refreshToken) {
|
|
60
|
+
try {
|
|
61
|
+
const refreshedAccessToken = await this.refreshAccessToken(
|
|
62
|
+
refreshToken
|
|
63
|
+
);
|
|
64
|
+
await this.getAccessTokenSetCookie(refreshedAccessToken);
|
|
65
|
+
const payload = this.JWT_MANAGER.decode(refreshedAccessToken);
|
|
66
|
+
if (payload) {
|
|
67
|
+
return payload;
|
|
68
|
+
}
|
|
69
|
+
} catch (e) {
|
|
70
|
+
if (e instanceof Error) {
|
|
71
|
+
console.log(e.message);
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async signIn({ id, password }) {
|
|
78
|
+
const credential = await this.repository.findCredentialById(id);
|
|
79
|
+
if (!credential) {
|
|
80
|
+
throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
|
|
81
|
+
}
|
|
82
|
+
if (!await bcryptjs.compare(password, credential.password)) {
|
|
83
|
+
throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
|
|
84
|
+
}
|
|
85
|
+
const user = await this.repository.findUserById(credential.userId);
|
|
86
|
+
if (!user) {
|
|
87
|
+
throw Error("\uD68C\uC6D0 \uC815\uBCF4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
88
|
+
}
|
|
89
|
+
const { accessToken, refreshToken } = await this.issueTokenPair(user);
|
|
90
|
+
return {
|
|
91
|
+
accessToken,
|
|
92
|
+
refreshToken
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async issueAccessToken(user) {
|
|
96
|
+
return this.JWT_MANAGER.signAccessToken({
|
|
97
|
+
userId: user.id,
|
|
98
|
+
role: user.role,
|
|
99
|
+
name: user.name
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
async issueTokenPair(user) {
|
|
103
|
+
const refreshToken = await this.JWT_MANAGER.signRefreshToken({
|
|
104
|
+
userId: user.id,
|
|
105
|
+
role: user.role,
|
|
106
|
+
name: user.name
|
|
107
|
+
});
|
|
108
|
+
await this.repository.updateUserRefreshToken(
|
|
109
|
+
user.id,
|
|
110
|
+
await bcryptjs.hash(refreshToken, 10)
|
|
111
|
+
);
|
|
112
|
+
const accessToken = await this.issueAccessToken(user);
|
|
113
|
+
return { refreshToken, accessToken };
|
|
114
|
+
}
|
|
115
|
+
async refreshAccessToken(refreshToken) {
|
|
116
|
+
const payload = await this.JWT_MANAGER.verifyRefreshToken(refreshToken);
|
|
117
|
+
if (!payload) {
|
|
118
|
+
throw new Error("\uD1A0\uD070\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
|
|
119
|
+
}
|
|
120
|
+
const { userId } = payload;
|
|
121
|
+
if (typeof userId !== "string") {
|
|
122
|
+
throw new Error("\uD1A0\uD070\uC774 \uC704\uC870\uB418\uC5C8\uC2B5\uB2C8\uB2E4.");
|
|
123
|
+
}
|
|
124
|
+
const user = await this.repository.findUserById(userId);
|
|
125
|
+
if (!user) {
|
|
126
|
+
throw Error("\uC774\uC6A9\uC790\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.");
|
|
127
|
+
}
|
|
128
|
+
if (!user.refreshToken) {
|
|
129
|
+
throw Error("\uC778\uC99D \uC815\uBCF4\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.");
|
|
130
|
+
}
|
|
131
|
+
if (await bcryptjs.compare(user.refreshToken, refreshToken)) {
|
|
132
|
+
throw Error("\uD1A0\uD070\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
|
|
133
|
+
}
|
|
134
|
+
const accessToken = await this.issueAccessToken(user);
|
|
135
|
+
return accessToken;
|
|
136
|
+
}
|
|
137
|
+
async getAccessTokenSetCookie(accessToken) {
|
|
138
|
+
return ACCESS_TOKEN_COOKIE.serialize(accessToken, {
|
|
139
|
+
expires: accessToken ? this.JWT_MANAGER.getExpirationTime(accessToken) : /* @__PURE__ */ new Date(0)
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
async getRefreshTokenSetCookie(refreshToken) {
|
|
143
|
+
return REFRESH_TOKEN_COOKIE.serialize(refreshToken, {
|
|
144
|
+
expires: refreshToken ? this.JWT_MANAGER.getExpirationTime(refreshToken) : /* @__PURE__ */ new Date(0)
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
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(
|
|
161
|
+
provider,
|
|
162
|
+
info.id
|
|
163
|
+
);
|
|
164
|
+
if (thirdPartyAuth) {
|
|
165
|
+
const user = await this.repository.findUserById(thirdPartyAuth.userId);
|
|
166
|
+
if (user) {
|
|
167
|
+
return user;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
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
|
+
}
|
|
211
|
+
};
|
|
212
|
+
export {
|
|
213
|
+
ACCESS_TOKEN_COOKIE,
|
|
214
|
+
ACCESS_TOKEN_KEY,
|
|
215
|
+
AuthService,
|
|
216
|
+
REFRESH_TOKEN_COOKIE,
|
|
217
|
+
REFRESH_TOKEN_KEY
|
|
218
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
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-kit/client/google_login_button.tsx
|
|
31
|
+
var google_login_button_exports = {};
|
|
32
|
+
__export(google_login_button_exports, {
|
|
33
|
+
GoogleLoginButton: () => GoogleLoginButton
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(google_login_button_exports);
|
|
36
|
+
var import_react = __toESM(require("react"));
|
|
37
|
+
var import_fc = require("react-icons/fc");
|
|
38
|
+
var import_react_router = require("react-router");
|
|
39
|
+
function GoogleLoginButton({
|
|
40
|
+
className = "max-w-[300px] w-full",
|
|
41
|
+
GOOGLE_CLIENT_ID,
|
|
42
|
+
GOOGLE_REDIRECT_URI
|
|
43
|
+
}) {
|
|
44
|
+
const [searchParams] = (0, import_react_router.useSearchParams)();
|
|
45
|
+
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
|
+
{
|
|
57
|
+
href: href.toString(),
|
|
58
|
+
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
|
+
},
|
|
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")
|
|
62
|
+
));
|
|
63
|
+
}
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
GoogleLoginButton
|
|
67
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/auth-kit/client/google_login_button.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { FcGoogle } from "react-icons/fc";
|
|
4
|
+
import { useSearchParams } from "react-router";
|
|
5
|
+
function GoogleLoginButton({
|
|
6
|
+
className = "max-w-[300px] w-full",
|
|
7
|
+
GOOGLE_CLIENT_ID,
|
|
8
|
+
GOOGLE_REDIRECT_URI
|
|
9
|
+
}) {
|
|
10
|
+
const [searchParams] = useSearchParams();
|
|
11
|
+
const redirectUrl = searchParams.get("redirectUrl") || "";
|
|
12
|
+
const googleClientId = GOOGLE_CLIENT_ID || "";
|
|
13
|
+
const googleRedirectUrl = GOOGLE_REDIRECT_URI || "";
|
|
14
|
+
const href = new URL("https://accounts.google.com/o/oauth2/v2/auth");
|
|
15
|
+
href.searchParams.append("client_id", googleClientId);
|
|
16
|
+
href.searchParams.append("redirect_uri", googleRedirectUrl);
|
|
17
|
+
href.searchParams.append("response_type", "code");
|
|
18
|
+
href.searchParams.append("scope", "email profile");
|
|
19
|
+
href.searchParams.append("state", redirectUrl);
|
|
20
|
+
return /* @__PURE__ */ React.createElement("div", { className }, /* @__PURE__ */ React.createElement(
|
|
21
|
+
"a",
|
|
22
|
+
{
|
|
23
|
+
href: href.toString(),
|
|
24
|
+
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"
|
|
25
|
+
},
|
|
26
|
+
/* @__PURE__ */ React.createElement(FcGoogle, null),
|
|
27
|
+
/* @__PURE__ */ React.createElement("p", { className: "text-[14px] text-black absolute left-0 right-0 text-center" }, "\uAD6C\uAE00\uB85C \uACC4\uC18D\uD558\uAE30")
|
|
28
|
+
));
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
GoogleLoginButton
|
|
32
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
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-kit/client/redirect_page.tsx
|
|
31
|
+
var redirect_page_exports = {};
|
|
32
|
+
__export(redirect_page_exports, {
|
|
33
|
+
RedirectPage: () => RedirectPage
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(redirect_page_exports);
|
|
36
|
+
var import_react = __toESM(require("react"));
|
|
37
|
+
var import_react2 = require("react");
|
|
38
|
+
var import_react_router = require("react-router");
|
|
39
|
+
function RedirectPage() {
|
|
40
|
+
const navigate = (0, import_react_router.useNavigate)();
|
|
41
|
+
(0, import_react2.useEffect)(() => {
|
|
42
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
43
|
+
const redirectUrl = searchParams.get("redirectUrl") || new URL("/", window.location.origin).toString();
|
|
44
|
+
if (redirectUrl) {
|
|
45
|
+
navigate(redirectUrl);
|
|
46
|
+
}
|
|
47
|
+
}, [navigate]);
|
|
48
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null);
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
RedirectPage
|
|
53
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/auth-kit/client/redirect_page.tsx
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { useNavigate } from "react-router";
|
|
5
|
+
function RedirectPage() {
|
|
6
|
+
const navigate = useNavigate();
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
9
|
+
const redirectUrl = searchParams.get("redirectUrl") || new URL("/", window.location.origin).toString();
|
|
10
|
+
if (redirectUrl) {
|
|
11
|
+
navigate(redirectUrl);
|
|
12
|
+
}
|
|
13
|
+
}, [navigate]);
|
|
14
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null);
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
RedirectPage
|
|
18
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AuthService } from './auth_service.mjs';
|
|
2
|
+
import 'jose';
|
|
3
|
+
import 'react-router';
|
|
4
|
+
import './jwt.mjs';
|
|
5
|
+
import '../file-kit/object_storage.mjs';
|
|
6
|
+
import '@aws-sdk/client-s3';
|
|
7
|
+
import './repository.mjs';
|
|
8
|
+
|
|
9
|
+
declare class GoogleAuth {
|
|
10
|
+
AUTH: AuthService;
|
|
11
|
+
GOOGLE_CLIENT_ID: string;
|
|
12
|
+
GOOGLE_CLIENT_SECRET: string;
|
|
13
|
+
GOOGLE_REDIRECT_URI: string;
|
|
14
|
+
constructor(AUTH: AuthService, GOOGLE_CLIENT_ID: string, GOOGLE_CLIENT_SECRET: string, GOOGLE_REDIRECT_URI: string);
|
|
15
|
+
signIn(code: string): Promise<{
|
|
16
|
+
user: {
|
|
17
|
+
id: string;
|
|
18
|
+
role: string;
|
|
19
|
+
name: string;
|
|
20
|
+
refreshToken: string | null;
|
|
21
|
+
};
|
|
22
|
+
accessToken: string;
|
|
23
|
+
refreshToken: string;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { GoogleAuth };
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import { AuthService } from
|
|
2
|
-
|
|
1
|
+
import { AuthService } from './auth_service.js';
|
|
2
|
+
import 'jose';
|
|
3
|
+
import 'react-router';
|
|
4
|
+
import './jwt.js';
|
|
5
|
+
import '../file-kit/object_storage.js';
|
|
6
|
+
import '@aws-sdk/client-s3';
|
|
7
|
+
import './repository.js';
|
|
8
|
+
|
|
9
|
+
declare class GoogleAuth {
|
|
3
10
|
AUTH: AuthService;
|
|
4
11
|
GOOGLE_CLIENT_ID: string;
|
|
5
12
|
GOOGLE_CLIENT_SECRET: string;
|
|
@@ -16,3 +23,5 @@ export declare class GoogleAuth {
|
|
|
16
23
|
refreshToken: string;
|
|
17
24
|
}>;
|
|
18
25
|
}
|
|
26
|
+
|
|
27
|
+
export { GoogleAuth };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/auth-kit/google_auth.tsx
|
|
21
|
+
var google_auth_exports = {};
|
|
22
|
+
__export(google_auth_exports, {
|
|
23
|
+
GoogleAuth: () => GoogleAuth
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(google_auth_exports);
|
|
26
|
+
|
|
27
|
+
// src/http-kit/response.ts
|
|
28
|
+
var createJsonResponse = (status) => {
|
|
29
|
+
return (data = {}, init) => {
|
|
30
|
+
return Response.json(data, { status, ...init });
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
var OK = createJsonResponse(200);
|
|
34
|
+
var CREATED = createJsonResponse(201);
|
|
35
|
+
var ACCEPTED = createJsonResponse(202);
|
|
36
|
+
var createException = (status, defaultMessage = "\uC624\uB958\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4.") => {
|
|
37
|
+
return (message = defaultMessage, init) => {
|
|
38
|
+
return createJsonResponse(status)({ message }, init);
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
var BAD_REQUEST = createException(400, "\uC694\uCCAD\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
|
|
42
|
+
var UNAUTHORIZED = createException(401, "\uC778\uC99D\uC774 \uD544\uC694\uD569\uB2C8\uB2E4.");
|
|
43
|
+
var FORBIDDEN = createException(403, "\uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
44
|
+
var NOT_FOUND = createException(
|
|
45
|
+
404,
|
|
46
|
+
"\uC694\uCCAD\uD55C \uB9AC\uC18C\uC2A4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
47
|
+
);
|
|
48
|
+
var METHOD_NOT_ALLOWED = createException(
|
|
49
|
+
405,
|
|
50
|
+
"\uBA54\uC11C\uB4DC\uB97C \uC0AC\uC6A9\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
51
|
+
);
|
|
52
|
+
var NOT_ACCEPTABLE = createException(
|
|
53
|
+
406,
|
|
54
|
+
"\uC694\uCCAD\uD55C \uD615\uC2DD\uC744 \uC0AC\uC6A9\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
55
|
+
);
|
|
56
|
+
var REQUEST_TIMEOUT = createException(
|
|
57
|
+
408,
|
|
58
|
+
"\uC694\uCCAD \uC2DC\uAC04\uC774 \uCD08\uACFC\uB418\uC5C8\uC2B5\uB2C8\uB2E4."
|
|
59
|
+
);
|
|
60
|
+
var CONFLICT = createException(409, "\uC694\uCCAD\uC774 \uCDA9\uB3CC\uD588\uC2B5\uB2C8\uB2E4.");
|
|
61
|
+
var UNPROCESSABLE_ENTITY = createException(
|
|
62
|
+
422,
|
|
63
|
+
"\uCC98\uB9AC\uD560 \uC218 \uC5C6\uB294 \uC5D4\uD2F0\uD2F0\uC785\uB2C8\uB2E4."
|
|
64
|
+
);
|
|
65
|
+
var TOO_MANY_REQUESTS = createException(429, "\uC694\uCCAD\uC774 \uB108\uBB34 \uB9CE\uC2B5\uB2C8\uB2E4.");
|
|
66
|
+
var INTERNAL_SERVER_ERROR = createException(
|
|
67
|
+
500,
|
|
68
|
+
"\uC608\uAE30\uCE58 \uBABB\uD55C \uC624\uB958\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4."
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// src/auth-kit/google_auth.tsx
|
|
72
|
+
var GoogleAuth = class {
|
|
73
|
+
AUTH;
|
|
74
|
+
GOOGLE_CLIENT_ID;
|
|
75
|
+
GOOGLE_CLIENT_SECRET;
|
|
76
|
+
GOOGLE_REDIRECT_URI;
|
|
77
|
+
constructor(AUTH, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_REDIRECT_URI) {
|
|
78
|
+
this.GOOGLE_CLIENT_ID = GOOGLE_CLIENT_ID;
|
|
79
|
+
this.GOOGLE_CLIENT_SECRET = GOOGLE_CLIENT_SECRET;
|
|
80
|
+
this.GOOGLE_REDIRECT_URI = GOOGLE_REDIRECT_URI;
|
|
81
|
+
this.AUTH = AUTH;
|
|
82
|
+
}
|
|
83
|
+
async signIn(code) {
|
|
84
|
+
const tokenRes = await fetch("https://oauth2.googleapis.com/token", {
|
|
85
|
+
method: "POST",
|
|
86
|
+
headers: {
|
|
87
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
88
|
+
},
|
|
89
|
+
body: new URLSearchParams({
|
|
90
|
+
code,
|
|
91
|
+
client_id: this.GOOGLE_CLIENT_ID,
|
|
92
|
+
client_secret: this.GOOGLE_CLIENT_SECRET,
|
|
93
|
+
redirect_uri: this.GOOGLE_REDIRECT_URI,
|
|
94
|
+
grant_type: "authorization_code"
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
if (!tokenRes.ok) {
|
|
98
|
+
if (process.env.NODE_ENV === "development") {
|
|
99
|
+
throw INTERNAL_SERVER_ERROR(
|
|
100
|
+
`\uAD6C\uAE00 \uD1A0\uD070 \uBC1C\uAE09\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4. status: ${tokenRes.status}, message: ${await tokenRes.text()}`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
throw INTERNAL_SERVER_ERROR("\uC778\uC99D\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4.");
|
|
104
|
+
}
|
|
105
|
+
const { access_token } = await tokenRes.json();
|
|
106
|
+
const userRes = await fetch(
|
|
107
|
+
"https://www.googleapis.com/oauth2/v1/userinfo",
|
|
108
|
+
{
|
|
109
|
+
headers: {
|
|
110
|
+
Authorization: `Bearer ${access_token}`
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
if (!userRes.ok) {
|
|
115
|
+
throw BAD_REQUEST("\uC720\uC800 \uC815\uBCF4\uB97C \uAC00\uC838\uC624\uB294\uB370 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4.");
|
|
116
|
+
}
|
|
117
|
+
const { id, email, name, picture } = await userRes.json();
|
|
118
|
+
const user = await this.AUTH.findUser("google", {
|
|
119
|
+
id,
|
|
120
|
+
email,
|
|
121
|
+
name,
|
|
122
|
+
picture
|
|
123
|
+
});
|
|
124
|
+
if (!user) {
|
|
125
|
+
throw createJsonResponse(404)({
|
|
126
|
+
provider: "google",
|
|
127
|
+
id,
|
|
128
|
+
name,
|
|
129
|
+
picture,
|
|
130
|
+
message: "\uC0AC\uC6A9\uC790\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const { accessToken, refreshToken } = await this.AUTH.issueTokenPair(user);
|
|
134
|
+
return {
|
|
135
|
+
user,
|
|
136
|
+
accessToken,
|
|
137
|
+
refreshToken
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
142
|
+
0 && (module.exports = {
|
|
143
|
+
GoogleAuth
|
|
144
|
+
});
|