Skip to content

Commit eedf34e

Browse files
authored
Merge pull request #439 from boostcampwm-2024/feat/google-github-oauth
✨ feat: OAuth 로그인 API 연동 및 백엔드 보완
2 parents 0a9fc27 + 5a245b8 commit eedf34e

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

client/src/components/auth/AuthSocialLoginButtons.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ import { Button } from "@/components/ui/button.tsx";
77
import { useCustomToast } from "@/hooks/common/useCustomToast.ts";
88

99
import { TOAST_MESSAGES } from "@/constants/messages.ts";
10+
import { BASE_URL, OAUTH } from "@/constants/endpoints.ts";
1011

1112
export const AuthSocialLoginButtons = () => {
1213
const { toast } = useCustomToast();
13-
const handleSocialLogin = () => {
14+
15+
const handleSocialLogin = (provider: "google" | "github") => {
16+
window.location.href = `${BASE_URL}${OAUTH.LOGIN}?type=${provider}`;
17+
};
18+
19+
const handleNotPrepared = () => {
1420
toast(TOAST_MESSAGES.SERVICE_NOT_PREPARED);
1521
};
1622

@@ -26,19 +32,19 @@ export const AuthSocialLoginButtons = () => {
2632
</div>
2733

2834
<div className="grid gap-2">
29-
<Button variant="outline" className="w-full" onClick={handleSocialLogin}>
35+
<Button variant="outline" className="w-full" onClick={() => handleSocialLogin("github")}>
3036
<GitHub />
3137
<span className="text-muted-foreground">Github로 계속하기</span>
3238
</Button>
33-
<Button variant="outline" className="w-full" onClick={handleSocialLogin}>
39+
<Button variant="outline" className="w-full" onClick={() => handleSocialLogin("google")}>
3440
<Google />
3541
<span className="text-muted-foreground">Google로 계속하기</span>
3642
</Button>
37-
<Button variant="outline" className="w-full" onClick={handleSocialLogin}>
43+
<Button variant="outline" className="w-full" onClick={handleNotPrepared}>
3844
<Naver className="text-[#03C75A]" />
3945
<span className="text-muted-foreground">네이버로 계속하기</span>
4046
</Button>
41-
<Button variant="outline" className="w-full" onClick={handleSocialLogin}>
47+
<Button variant="outline" className="w-full" onClick={handleNotPrepared}>
4248
<Kakao className="text-[#FEE500]" />
4349
<span className="text-muted-foreground">카카오로 계속하기</span>
4450
</Button>

client/src/constants/endpoints.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ export const USER = {
4040
LOGIN: "/api/user/login",
4141
CERTIFICATE: "/api/user/certificate",
4242
};
43+
44+
export const OAUTH = {
45+
LOGIN: "/api/oauth",
46+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { useEffect } from "react";
2+
import { useLocation, useNavigate } from "react-router-dom";
3+
4+
import { useAuthStore } from "@/store/useAuthStore.ts";
5+
6+
export const OAuthSuccessPage = () => {
7+
const navigate = useNavigate();
8+
const location = useLocation();
9+
const { setUserFromToken } = useAuthStore();
10+
11+
useEffect(() => {
12+
const searchParams = new URLSearchParams(location.search);
13+
const accessToken = searchParams.get("token");
14+
15+
if (accessToken) {
16+
setUserFromToken(accessToken);
17+
navigate("/", { replace: true });
18+
} else {
19+
navigate("/signin", { replace: true });
20+
}
21+
}, [location, navigate, setUserFromToken]);
22+
23+
return (
24+
<div className="flex h-screen items-center justify-center">
25+
<p className="text-lg">로그인 처리 중입니다...</p>
26+
</div>
27+
);
28+
};

client/src/routes/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const Profile = lazy(() => import("@/pages/Profile"));
1313
const SignIn = lazy(() => import("@/pages/SignIn"));
1414
const SignUp = lazy(() => import("@/pages/SignUp"));
1515
const UserCertificate = lazy(() => import("@/pages/UserCertificate"));
16+
const OAuthSuccessPage = lazy(() => import("@/pages/OAuthSuccessPage"));
1617

1718
interface RouterProps {
1819
location: Location;
@@ -63,6 +64,14 @@ export const AppRouter = ({ location, state }: RouterProps) => {
6364
</Suspense>
6465
}
6566
/>
67+
<Route
68+
path="/oauth-success"
69+
element={
70+
<Suspense fallback={<Loading />}>
71+
<OAuthSuccessPage />
72+
</Suspense>
73+
}
74+
/>
6675
<Route
6776
path="/user/certificate"
6877
element={

server/src/user/module/user.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { UserScheduler } from '../scheduler/user.scheduler';
3232
google,
3333
github,
3434
}),
35-
inject: [GoogleOAuthProvider],
35+
inject: [GoogleOAuthProvider, GithubOAuthProvider],
3636
},
3737
],
3838
exports: [UserRepository, UserService],

0 commit comments

Comments
 (0)