File tree Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import TestLoginModal from '@/components/testLogin/TestLoginModal';
2626
2727import { useSheetStore } from './store/sheetStore' ;
2828import AnimatedLayout from '@/layouts/AnimatedLayout' ;
29+ import KaKaoRedirection from '@/components/KaKaoRedirection' ;
2930
3031function App ( ) {
3132 const location = useLocation ( ) ;
@@ -83,6 +84,8 @@ function App() {
8384 < Route path = "/mypage/blocklist" element = { < BlockList /> } />
8485 < Route path = "/user/:userId" element = { < UserProfile isMyPage = { false } /> } />
8586 </ Route >
87+
88+ < Route path = "/auth/login/kakao/callback" element = { < KaKaoRedirection /> } />
8689 < Route path = "*" element = { < NotFound /> } />
8790 </ Route >
8891 </ Routes >
Original file line number Diff line number Diff line change @@ -40,3 +40,9 @@ export const reissueToken = async () => {
4040 }
4141 return data ;
4242} ;
43+
44+ // 카카오 로그인
45+ export const getKakaoLogin = async ( code : string ) => {
46+ const { data } = await axiosInstance . get ( '/auth/login/kakao' , { params : { code } } ) ;
47+ return data ;
48+ } ;
Original file line number Diff line number Diff line change 1+ import { getKakaoLogin } from '@/apis/auth' ;
2+ import { useAuthStore } from '@/store/authStore' ;
3+ import React , { useEffect } from 'react' ;
4+ import { useNavigate } from 'react-router' ;
5+
6+ function KaKaoRedirection ( ) {
7+ const navigate = useNavigate ( ) ;
8+ const code = new URL ( window . location . href ) . searchParams . get ( 'code' ) ;
9+ const { setAccessToken } = useAuthStore ;
10+
11+ const handleKaKaoLogin = async ( ) => {
12+ try {
13+ const data = await getKakaoLogin ( code as string ) ;
14+ // 토큰 저장하기
15+ navigate ( '/home' ) ;
16+ } catch ( error ) { }
17+ } ;
18+
19+ useEffect ( ( ) => {
20+ handleKaKaoLogin ( ) ;
21+ } , [ ] ) ;
22+ return < div > KaKaoRedirection</ div > ;
23+ }
24+
25+ export default KaKaoRedirection ;
Original file line number Diff line number Diff line change @@ -71,6 +71,13 @@ export default function Login() {
7171 resetInputs ( ) ;
7272 } ;
7373
74+ const handleKakaoLogin = ( ) => {
75+ const KAKAO_CLIENT_ID = import . meta. env . VITE_KAKAO_CLIENT_ID ;
76+ const KAKAO_REDIRECT_URI = import . meta. env . VITE_KAKAO_REDIRECT_URI ;
77+ const link = `https://kauth.kakao.com/oauth/authorize?client_id=${ KAKAO_CLIENT_ID } &redirect_uri=${ KAKAO_REDIRECT_URI } &response_type=code` ;
78+ window . location . href = link ;
79+ } ;
80+
7481 const renderButtonContent = ( ) => {
7582 if ( isLoading ) {
7683 return < SpinLoading /> ;
@@ -119,7 +126,10 @@ export default function Login() {
119126
120127 < div className = "flex flex-col gap-3 items-center w-full mt-2.5 " >
121128 { /* 소셜 로그인 */ }
122- < Button className = "bg-[#FEE500] text-gray-80 gap-1.5 hover:bg-[#fded63]" >
129+ < Button
130+ className = "bg-[#FEE500] text-gray-80 gap-1.5 hover:bg-[#fded63]"
131+ onClick = { handleKakaoLogin }
132+ >
123133 < img className = "w-4" src = { kakao } alt = "카카오 아이콘" />
124134 < span className = "text-black/85" > 카카오로 시작하기</ span >
125135 </ Button >
You can’t perform that action at this time.
0 commit comments