Skip to content

Commit

Permalink
FIX: kakao app login 실패시 REST login 제공
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperRyou committed Jun 20, 2024
1 parent 805a64f commit fba4c00
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/assist/buttonwrapper/KakaoLoginButtonWrapper.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<FlexBox className="px-4 w-full justify-center">
<div className="w-full max-w-[360px]">
<LoginButton type="kakao" onClick={kakaoSDKLogin} />
<LoginButton
type="kakao"
onClick={() => {
alert(clickedNumber);
if (clickedNumber === 0) kakaoSDKLogin();
else kakaoRESTLogin();
setClickedNumber(clickedNumber + 1);
}}
/>
</div>
</FlexBox>
);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/oauth/kakao.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function Kakao() {
const { mutate: postKakaoLoginMutate } = useKakaoLogin();

useEffect(() => {
if (code && state) {
if (code) {
postKakaoLoginMutate({
data: {
code,
Expand Down

0 comments on commit fba4c00

Please sign in to comment.