File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ "use client" ;
2+
3+ import { useEffect } from "react" ;
4+ import { useRouter , useSearchParams } from "next/navigation" ;
5+
6+ export default function KakaoCallbackPage ( ) {
7+ const router = useRouter ( ) ;
8+ const params = useSearchParams ( ) ;
9+ const code = params . get ( "code" ) ;
10+
11+ useEffect ( ( ) => {
12+ if ( ! code ) return ;
13+
14+ const login = async ( ) => {
15+ const res = await fetch (
16+ `${ process . env . NEXT_PUBLIC_API_BASE_URL } /api/v1/auth/login/google?code=${ code } ` ,
17+ {
18+ method : "GET" ,
19+ credentials : "include" , // 쿠키 방식이면 필수
20+ }
21+ ) ;
22+
23+ if ( res . ok ) {
24+ router . replace ( "/home" ) ;
25+ } else {
26+ router . replace ( "/sign-in" ) ;
27+ }
28+ } ;
29+
30+ login ( ) ;
31+ } , [ code , router ] ) ;
32+
33+ return < p > 구글 로그인 처리 중...</ p > ;
34+ }
Original file line number Diff line number Diff line change 1+ "use client" ;
2+
3+ import { useEffect } from "react" ;
4+ import { useRouter , useSearchParams } from "next/navigation" ;
5+
6+ export default function KakaoCallbackPage ( ) {
7+ const router = useRouter ( ) ;
8+ const params = useSearchParams ( ) ;
9+ const code = params . get ( "code" ) ;
10+
11+ useEffect ( ( ) => {
12+ if ( ! code ) return ;
13+
14+ const login = async ( ) => {
15+ const res = await fetch (
16+ `${ process . env . NEXT_PUBLIC_API_BASE_URL } /api/v1/auth/login/kakao?code=${ code } ` ,
17+ {
18+ method : "GET" ,
19+ credentials : "include" , // 쿠키 방식이면 필수
20+ }
21+ ) ;
22+
23+ if ( res . ok ) {
24+ router . replace ( "/home" ) ;
25+ } else {
26+ router . replace ( "/sign-in" ) ;
27+ }
28+ } ;
29+
30+ login ( ) ;
31+ } , [ code , router ] ) ;
32+
33+ return < p > 카카오 로그인 처리 중...</ p > ;
34+ }
Original file line number Diff line number Diff line change 1+ "use client" ;
2+
13import { MessageCircle } from "lucide-react" ;
24import { Button } from "@/components/ui/button" ;
35import Image from "next/image" ;
46
7+ const KAKAO_AUTH_URL =
8+ "https://kauth.kakao.com/oauth/authorize" +
9+ `?response_type=code` +
10+ `&client_id=${ process . env . NEXT_PUBLIC_KAKAO_CLIENT_ID } ` +
11+ `&redirect_uri=${ process . env . NEXT_PUBLIC_KAKAO_REDIRECT_URI } ` ;
12+
13+ const GOOGLE_AUTH_URL =
14+ "https://accounts.google.com/o/oauth2/v2/auth" +
15+ `?response_type=code` +
16+ `&client_id=${ process . env . NEXT_PUBLIC_GOOGLE_CLIENT_ID } ` +
17+ `&redirect_uri=${ process . env . NEXT_PUBLIC_GOOGLE_REDIRECT_URI } ` +
18+ `&scope=openid%20email%20profile` ;
19+
520export default function SocialButton ( ) {
21+ const handleKakaoLogin = ( ) => {
22+ window . location . href = KAKAO_AUTH_URL ;
23+ } ;
24+
25+ const handleGoogleLogin = ( ) => {
26+ window . location . href = GOOGLE_AUTH_URL ;
27+ } ;
28+
629 return (
730 < >
831 < div className = "social bg-bg-main flex w-full flex-col gap-3" >
@@ -11,6 +34,7 @@ export default function SocialButton() {
1134 variant = "default"
1235 size = "lg"
1336 asChild = { false }
37+ onClick = { handleKakaoLogin }
1438 >
1539 < MessageCircle />
1640 Kakao로 계속하기
@@ -21,6 +45,7 @@ export default function SocialButton() {
2145 variant = "outline"
2246 size = "lg"
2347 asChild = { false }
48+ onClick = { handleGoogleLogin }
2449 >
2550 < Image src = "/googleIcon.svg" alt = "Google icon" width = { 15 } height = { 15 } />
2651 Google로 계속하기
You can’t perform that action at this time.
0 commit comments