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.
- package/dist/auth/apple_auth.d.mts +38 -0
- package/dist/auth/apple_auth.d.ts +38 -0
- package/dist/{auth-kit → auth}/apple_auth.js +31 -18
- package/dist/auth/apple_auth.mjs +63 -0
- package/dist/{auth-kit/repository.d.mts → auth/auth_repository.d.mts} +6 -9
- package/dist/{auth-kit/repository.d.ts → auth/auth_repository.d.ts} +6 -9
- package/dist/{file-kit/repository.js → auth/auth_repository.js} +3 -3
- package/dist/{auth-kit → auth}/auth_service.d.mts +12 -22
- package/dist/{auth-kit → auth}/auth_service.d.ts +12 -22
- package/dist/{auth-kit → auth}/auth_service.js +30 -77
- package/dist/{auth-kit → auth}/auth_service.mjs +30 -77
- package/dist/auth/client/google_login_button.d.mts +7 -0
- package/dist/auth/client/google_login_button.d.ts +7 -0
- package/dist/{auth-kit → auth}/client/google_login_button.js +24 -19
- package/dist/auth/client/google_login_button.mjs +37 -0
- package/dist/auth/client/provider.d.mts +23 -0
- package/dist/auth/client/provider.d.ts +23 -0
- package/dist/auth/client/provider.js +137 -0
- package/dist/auth/client/provider.mjs +101 -0
- package/dist/{auth-kit → auth}/client/redirect_page.js +1 -1
- package/dist/{auth-kit → auth}/client/redirect_page.mjs +1 -1
- package/dist/auth/google_auth.d.mts +33 -0
- package/dist/auth/google_auth.d.ts +33 -0
- package/dist/{auth-kit → auth}/google_auth.js +23 -32
- package/dist/{auth-kit → auth}/google_auth.mjs +22 -31
- package/dist/auth/handlers/find_auth.d.mts +13 -0
- package/dist/auth/handlers/find_auth.d.ts +13 -0
- package/dist/{route/api/auth/route.js → auth/handlers/find_auth.js} +10 -10
- package/dist/{route/api/auth/route.mjs → auth/handlers/find_auth.mjs} +5 -5
- package/dist/auth/handlers/login.d.mts +13 -0
- package/dist/auth/handlers/login.d.ts +13 -0
- package/dist/{route/api/auth/login/route.js → auth/handlers/login.js} +17 -17
- package/dist/{route/api/auth/login/route.mjs → auth/handlers/login.mjs} +12 -12
- package/dist/auth/handlers/login_with_thirdparty.d.mts +15 -0
- package/dist/auth/handlers/login_with_thirdparty.d.ts +15 -0
- package/dist/{route/api/auth/login/[provider]/route.js → auth/handlers/login_with_thirdparty.js} +12 -27
- package/dist/{route/api/auth/login/[provider]/route.mjs → auth/handlers/login_with_thirdparty.mjs} +7 -22
- package/dist/auth/handlers/logout.d.mts +13 -0
- package/dist/auth/handlers/logout.d.ts +13 -0
- package/dist/{route/api/auth/logout/route.js → auth/handlers/logout.js} +15 -11
- package/dist/{route/api/auth/logout/route.mjs → auth/handlers/logout.mjs} +11 -7
- package/dist/auth/handlers/refresh.d.mts +13 -0
- package/dist/auth/handlers/refresh.d.ts +13 -0
- package/dist/{route/api/auth/refresh/route.js → auth/handlers/refresh.js} +12 -12
- package/dist/{route/api/auth/refresh/route.mjs → auth/handlers/refresh.mjs} +7 -7
- package/dist/auth/handlers/signup.d.mts +15 -0
- package/dist/auth/handlers/signup.d.ts +15 -0
- package/dist/auth/handlers/signup.js +135 -0
- package/dist/auth/handlers/signup.mjs +100 -0
- package/dist/auth/handlers/signup_with_thirdparty.d.mts +17 -0
- package/dist/auth/handlers/signup_with_thirdparty.d.ts +17 -0
- package/dist/auth/handlers/signup_with_thirdparty.js +123 -0
- package/dist/auth/handlers/signup_with_thirdparty.mjs +98 -0
- package/dist/auth/handlers/thirdparty_auth_callback.d.mts +16 -0
- package/dist/auth/handlers/thirdparty_auth_callback.d.ts +16 -0
- package/dist/{route/auth/callback/[provider]/route.js → auth/handlers/thirdparty_auth_callback.js} +54 -45
- package/dist/{route/auth/callback/[provider]/route.mjs → auth/handlers/thirdparty_auth_callback.mjs} +49 -40
- package/dist/{auth-kit/jwt.d.mts → auth/jwt_manager.d.mts} +11 -1
- package/dist/{auth-kit/jwt.d.ts → auth/jwt_manager.d.ts} +11 -1
- package/dist/{auth-kit/jwt.js → auth/jwt_manager.js} +25 -11
- package/dist/{auth-kit/jwt.mjs → auth/jwt_manager.mjs} +22 -8
- package/dist/auth/kakao_auth.d.mts +27 -0
- package/dist/auth/kakao_auth.d.ts +27 -0
- package/dist/auth/kakao_auth.js +56 -0
- package/dist/auth/kakao_auth.mjs +31 -0
- package/dist/auth/thirdparty_auth.d.mts +41 -0
- package/dist/auth/thirdparty_auth.d.ts +41 -0
- package/dist/{auth-kit/kakao_auth.js → auth/thirdparty_auth.js} +31 -33
- package/dist/{auth-kit/kakao_auth.mjs → auth/thirdparty_auth.mjs} +26 -28
- package/dist/{auth-kit → auth}/with_auth.d.mts +5 -6
- package/dist/{auth-kit → auth}/with_auth.d.ts +5 -6
- package/dist/{auth-kit → auth}/with_auth.js +26 -42
- package/dist/auth/with_auth.mjs +63 -0
- package/dist/date.d.mts +2 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +4 -2
- package/dist/date.mjs +2 -1
- package/dist/{file-kit → file}/cdn.js +1 -1
- package/dist/{file-kit → file}/cdn.mjs +1 -1
- package/dist/{file-kit → file}/client/drop_file_input.js +3 -3
- package/dist/{file-kit → file}/client/drop_file_input.mjs +3 -3
- package/dist/{file-kit → file}/client/file_upload_button.js +1 -1
- package/dist/{file-kit → file}/client/file_upload_button.mjs +1 -1
- package/dist/{file-kit → file}/client/file_uploader.js +3 -3
- package/dist/{file-kit → file}/client/file_uploader.mjs +2 -2
- package/dist/{file-kit → file}/client/format_size.js +1 -1
- package/dist/{file-kit → file}/client/format_size.mjs +1 -1
- package/dist/{file-kit → file}/client/metadata.js +1 -1
- package/dist/{file-kit → file}/client/metadata.mjs +1 -1
- package/dist/{file-kit/repository.d.mts → file/file_repository.d.mts} +4 -4
- package/dist/{file-kit/repository.d.ts → file/file_repository.d.ts} +4 -4
- package/dist/{auth-kit/repository.js → file/file_repository.js} +3 -3
- package/dist/file/file_service.d.mts +32 -0
- package/dist/file/file_service.d.ts +32 -0
- package/dist/{file-kit → file}/file_service.js +27 -21
- package/dist/file/file_service.mjs +41 -0
- package/dist/file/handlers/delete_file.d.mts +17 -0
- package/dist/file/handlers/delete_file.d.ts +17 -0
- package/dist/{route/api/files/[fileId]/route.js → file/handlers/delete_file.js} +15 -15
- package/dist/{route/api/files/[fileId]/route.mjs → file/handlers/delete_file.mjs} +10 -10
- package/dist/file/handlers/upload_file.d.mts +16 -0
- package/dist/file/handlers/upload_file.d.ts +16 -0
- package/dist/{route/api/files/route.js → file/handlers/upload_file.js} +13 -13
- package/dist/{route/api/files/route.mjs → file/handlers/upload_file.mjs} +8 -8
- package/dist/{file-kit → file}/object_storage.d.mts +3 -1
- package/dist/{file-kit → file}/object_storage.d.ts +3 -1
- package/dist/{file-kit → file}/object_storage.js +2 -2
- package/dist/{file-kit → file}/object_storage.mjs +2 -2
- package/dist/{file-kit → file}/responsive_image.d.mts +4 -4
- package/dist/{file-kit → file}/responsive_image.d.ts +4 -4
- package/dist/{file-kit → file}/responsive_image.js +18 -9
- package/dist/{file-kit → file}/responsive_image.mjs +18 -9
- package/dist/{http-kit → http}/index.js +5 -5
- package/dist/{http-kit → http}/index.mjs +1 -1
- package/dist/{http-kit → http}/response.js +1 -1
- package/dist/{http-kit → http}/response.mjs +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +1 -0
- package/dist/route/api.d.mts +15 -25
- package/dist/route/api.d.ts +15 -25
- package/dist/route/api.js +325 -178
- package/dist/route/api.mjs +314 -177
- package/dist/{seo-kit → seo}/seo.js +1 -1
- package/dist/{seo-kit → seo}/seo.mjs +1 -1
- package/package.json +74 -74
- package/dist/auth-kit/apple_auth.d.mts +0 -24
- package/dist/auth-kit/apple_auth.d.ts +0 -24
- package/dist/auth-kit/apple_auth.mjs +0 -50
- package/dist/auth-kit/client/google_login_button.d.mts +0 -9
- package/dist/auth-kit/client/google_login_button.d.ts +0 -9
- package/dist/auth-kit/client/google_login_button.mjs +0 -32
- package/dist/auth-kit/client/logout.d.mts +0 -3
- package/dist/auth-kit/client/logout.d.ts +0 -3
- package/dist/auth-kit/client/logout.js +0 -49
- package/dist/auth-kit/client/logout.mjs +0 -24
- package/dist/auth-kit/google_auth.d.mts +0 -27
- package/dist/auth-kit/google_auth.d.ts +0 -27
- package/dist/auth-kit/kakao_auth.d.mts +0 -24
- package/dist/auth-kit/kakao_auth.d.ts +0 -24
- package/dist/auth-kit/with_auth.mjs +0 -67
- package/dist/file-kit/file_service.d.mts +0 -26
- package/dist/file-kit/file_service.d.ts +0 -26
- package/dist/file-kit/file_service.mjs +0 -35
- package/dist/route/api/auth/login/_provider_/route.d.mts +0 -20
- package/dist/route/api/auth/login/_provider_/route.d.ts +0 -20
- package/dist/route/api/auth/login/route.d.mts +0 -14
- package/dist/route/api/auth/login/route.d.ts +0 -14
- package/dist/route/api/auth/logout/route.d.mts +0 -14
- package/dist/route/api/auth/logout/route.d.ts +0 -14
- package/dist/route/api/auth/refresh/route.d.mts +0 -13
- package/dist/route/api/auth/refresh/route.d.ts +0 -13
- package/dist/route/api/auth/route.d.mts +0 -13
- package/dist/route/api/auth/route.d.ts +0 -13
- package/dist/route/api/files/_fileId_/route.d.mts +0 -17
- package/dist/route/api/files/_fileId_/route.d.ts +0 -17
- package/dist/route/api/files/route.d.mts +0 -16
- package/dist/route/api/files/route.d.ts +0 -16
- package/dist/route/auth/callback/_provider_/route.d.mts +0 -20
- package/dist/route/auth/callback/_provider_/route.d.ts +0 -20
- /package/dist/{auth-kit/repository.mjs → auth/auth_repository.mjs} +0 -0
- /package/dist/{auth-kit → auth}/client/redirect_page.d.mts +0 -0
- /package/dist/{auth-kit → auth}/client/redirect_page.d.ts +0 -0
- /package/dist/{file-kit → file}/cdn.d.mts +0 -0
- /package/dist/{file-kit → file}/cdn.d.ts +0 -0
- /package/dist/{file-kit → file}/client/drop_file_input.d.mts +0 -0
- /package/dist/{file-kit → file}/client/drop_file_input.d.ts +0 -0
- /package/dist/{file-kit → file}/client/file_upload_button.d.mts +0 -0
- /package/dist/{file-kit → file}/client/file_upload_button.d.ts +0 -0
- /package/dist/{file-kit → file}/client/file_uploader.d.mts +0 -0
- /package/dist/{file-kit → file}/client/file_uploader.d.ts +0 -0
- /package/dist/{file-kit → file}/client/format_size.d.mts +0 -0
- /package/dist/{file-kit → file}/client/format_size.d.ts +0 -0
- /package/dist/{file-kit → file}/client/metadata.d.mts +0 -0
- /package/dist/{file-kit → file}/client/metadata.d.ts +0 -0
- /package/dist/{file-kit/repository.mjs → file/file_repository.mjs} +0 -0
- /package/dist/{http-kit → http}/index.d.mts +0 -0
- /package/dist/{http-kit → http}/index.d.ts +0 -0
- /package/dist/{http-kit → http}/response.d.mts +0 -0
- /package/dist/{http-kit → http}/response.d.ts +0 -0
- /package/dist/{seo-kit → seo}/seo.d.mts +0 -0
- /package/dist/{seo-kit → seo}/seo.d.ts +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// src/auth
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
authRepository;
|
|
20
|
+
jwtManager;
|
|
21
|
+
objectStorage;
|
|
23
22
|
constructor({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
authRepository,
|
|
24
|
+
jwtManager,
|
|
25
|
+
objectStorage
|
|
27
26
|
}) {
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
27
|
+
this.authRepository = authRepository;
|
|
28
|
+
this.jwtManager = jwtManager;
|
|
29
|
+
this.objectStorage = objectStorage;
|
|
31
30
|
}
|
|
32
31
|
async verify(request) {
|
|
33
|
-
const accessToken =
|
|
32
|
+
const accessToken = await this.getAccessTokenFromRequest(request);
|
|
34
33
|
if (accessToken) {
|
|
35
|
-
return this.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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 {
|
|
@@ -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
|
|
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
|
|
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
|
|
53
|
+
const { loginWithGoogle } = useAuth();
|
|
54
|
+
const [searchParams] = (0, import_react_router2.useSearchParams)();
|
|
45
55
|
const redirectUrl = searchParams.get("redirectUrl") || "";
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
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__ */
|
|
61
|
-
/* @__PURE__ */
|
|
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
|
|
30
|
+
// src/auth/client/redirect_page.tsx
|
|
31
31
|
var redirect_page_exports = {};
|
|
32
32
|
__export(redirect_page_exports, {
|
|
33
33
|
RedirectPage: () => RedirectPage
|
|
@@ -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 };
|