File tree Expand file tree Collapse file tree 3 files changed +22
-14
lines changed
Expand file tree Collapse file tree 3 files changed +22
-14
lines changed Original file line number Diff line number Diff line change 11const KakaoLoginButton = ( ) => {
2- const kakaoURL = `https://kauth.kakao.com/oauth/authorize?client_id=${ import . meta. env . VITE_KAKAO_REST_API_KEY } &redirect_uri=${ import . meta. env . VITE_KAKAO_REDIRECT_URI } &response_type=code` ;
2+ const kakaoRestApiKey = import . meta. env . VITE_KAKAO_REST_API_KEY ;
3+ const kakaoRedirectUrl = import . meta. env . VITE_KAKAO_REDIRECT_URI ;
4+
5+ const kakaoURL = `https://kauth.kakao.com/oauth/authorize?client_id=${ kakaoRestApiKey } &redirect_uri=${ kakaoRedirectUrl } &response_type=code` ;
36
47 const handleClick = ( ) => {
58 window . location . href = kakaoURL ;
@@ -9,7 +12,7 @@ const KakaoLoginButton = () => {
912 < button
1013 type = "button"
1114 onClick = { handleClick }
12- className = "flex justify-center items-center bg-[#F9E622] hover:opacity-80 rounded-lg w-[320px] h-[56px] font-bold text-black"
15+ className = "flex h-[56px] w-[320px] items-center justify-center rounded-lg bg-[#F9E622] font-bold text-black hover:opacity-80 "
1316 >
1417 카카오로 시작하기
1518 </ button >
Original file line number Diff line number Diff line change @@ -11,10 +11,10 @@ const KaKaoLogin = () => {
1111 const getTokenAndLogin = async ( ) => {
1212 if ( typeof code === "string" ) {
1313 try {
14- await login ( code ) ;
15- navigate ( "/" ) ;
14+ const res = await login ( code ) ;
15+ if ( res . ok ) navigate ( "/" ) ;
1616 } catch ( err ) {
17- console . error ( "카카오 로그인에 실패했습니다. ") ;
17+ navigate ( "/error ") ;
1818 }
1919 }
2020 } ;
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import instance from "@/api/axios";
55interface AuthStore {
66 isLoggedIn : boolean ;
77 accessToken : string | null ;
8- login : ( code : string ) => Promise < void > ;
8+ login : ( code : string ) => Promise < { ok : boolean } > ;
99 logout : ( ) => void ;
1010}
1111
@@ -16,22 +16,27 @@ const useAuthStore = create(
1616 accessToken : null ,
1717 login : async ( code : string ) => {
1818 try {
19- const res = await instance . get ( `/api/kakao/login?code=${ code } ` ) ;
20- if ( res . data ) {
21- set ( {
22- isLoggedIn : true ,
23- accessToken : res . data as string
24- } ) ;
25- }
19+ const res = await instance . get (
20+ `/api/kakao/login?code=${ code } `
21+ // + "&redirectUrl=https://localhost:5173/kakao-login"
22+ ) ;
23+ set ( {
24+ isLoggedIn : true ,
25+ accessToken : res . data as string
26+ } ) ;
27+ return {
28+ ok : true
29+ } ;
2630 } catch ( error ) {
27- console . error ( "Error during login:" , error ) ;
31+ throw error ;
2832 }
2933 } ,
3034 logout : ( ) => {
3135 set ( {
3236 isLoggedIn : false ,
3337 accessToken : null
3438 } ) ;
39+ return { ok : true } ;
3540 }
3641 } ) ,
3742 {
You can’t perform that action at this time.
0 commit comments