From fba4c0064fa39500655affeebaf66bb532417a7a Mon Sep 17 00:00:00 2001 From: DeveloperRyou Date: Thu, 20 Jun 2024 20:03:52 +0900 Subject: [PATCH] =?UTF-8?q?FIX:=20kakao=20app=20login=20=EC=8B=A4=ED=8C=A8?= =?UTF-8?q?=EC=8B=9C=20REST=20login=20=EC=A0=9C=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../buttonwrapper/KakaoLoginButtonWrapper.tsx | 22 +++++++++++++++++-- src/pages/oauth/kakao.tsx | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/assist/buttonwrapper/KakaoLoginButtonWrapper.tsx b/src/assist/buttonwrapper/KakaoLoginButtonWrapper.tsx index 449e133..add0f65 100644 --- a/src/assist/buttonwrapper/KakaoLoginButtonWrapper.tsx +++ b/src/assist/buttonwrapper/KakaoLoginButtonWrapper.tsx @@ -1,24 +1,42 @@ import { createRandomString } from "@/libs/createRandomId"; import LoginButton from "@modules/components/button/LoginButton"; import FlexBox from "@modules/layout/FlexBox"; +import { useRouter } from "next/router"; +import { useState } from "react"; function KakaoLoginButtonWrapper() { + const { push } = useRouter(); + const [clickedNumber, setClickedNumber] = useState(0); + const redirectUri = `${window.location.origin}/oauth/kakao`; const kakaoSDKLogin = () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const kakao = (window as any).Kakao; if (!kakao?.isInitialized()) { kakao?.init(process.env.NEXT_PUBLIC_KAKAO_JS_KEY); } - const redirectUri = `${window.location.origin}/oauth/kakao`; kakao?.Auth?.authorize({ redirectUri, state: createRandomString(32), }); }; + const kakaoRESTLogin = () => { + push( + `https://kauth.kakao.com/oauth/authorize?redirect_uri=${redirectUri}&client_id=${process.env.NEXT_PUBLIC_KAKAO_REST_KEY}&response_type=code`, + ); + }; + return (
- + { + alert(clickedNumber); + if (clickedNumber === 0) kakaoSDKLogin(); + else kakaoRESTLogin(); + setClickedNumber(clickedNumber + 1); + }} + />
); diff --git a/src/pages/oauth/kakao.tsx b/src/pages/oauth/kakao.tsx index c2f8244..0e0651d 100644 --- a/src/pages/oauth/kakao.tsx +++ b/src/pages/oauth/kakao.tsx @@ -9,7 +9,7 @@ export default function Kakao() { const { mutate: postKakaoLoginMutate } = useKakaoLogin(); useEffect(() => { - if (code && state) { + if (code) { postKakaoLoginMutate({ data: { code,