-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 카카오 로그인 시 인가 코드를 받아와 백엔드로 전송해주는 login/kakao 페이지(프로토타입) 추가 #5
feat: 카카오 로그인 시 인가 코드를 받아와 백엔드로 전송해주는 login/kakao 페이지(프로토타입) 추가
- Loading branch information
1 parent
306b3b5
commit 3d966ac
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { useEffect } from "react"; | ||
import axios from "axios"; | ||
import { useRouter } from "next/router"; | ||
import { useRecoilState } from "recoil"; | ||
import { signUpDataState } from "../../src/recoil/login/signUpState"; | ||
import Wrapper from "../../src/login/components/Wrapper"; | ||
|
||
const Kakao = () => { | ||
const router = useRouter(); | ||
const [signUpData, setSignUpData] = useRecoilState(signUpDataState); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
let code = new URL(window.location.href).searchParams.get("code"); | ||
|
||
if (code !== undefined) { | ||
try { | ||
const response = await axios.get( | ||
`https://api.dessert-gallery.site/users/login/kakao?code=${code}` | ||
); | ||
console.log(response.data); | ||
setSignUpData({ | ||
...signUpData, | ||
email: response.data.email, | ||
loginType: "KAKAO", | ||
}); | ||
|
||
if (response.data.responseCode === "200") { | ||
// 여기는 로그인 처리 후 메인페이지로 | ||
console.log(200); | ||
} else if (response.data.responseCode === "201") { | ||
// 여기는 신규 회원이니 회원가입으로 | ||
console.log(201); | ||
router.replace({ | ||
pathname: "/login/pick", | ||
}); | ||
} else { | ||
console.log("에러", response.data.responseCode); | ||
} | ||
} catch (error) { | ||
console.log("Error occurred:", error); | ||
} | ||
} | ||
}; | ||
|
||
const response = fetchData(); | ||
}, [router, setSignUpData, signUpData]); | ||
return <Wrapper>카카오 로그인 테스트 페이지</Wrapper>; | ||
}; | ||
|
||
export default Kakao; |