//index.html
<script
type="text/javascript"
src="//dapi.kakao.com/v2/maps/sdk.js?appkey=<JavaScript 키>&libraries=services"
></script>
</head>
<body>
<script src="https://developers.kakao.com/sdk/js/kakao.js"></script>
declare global {
interface Window {
kakao: any;
}
}
const Login = () => {
const CLIENT_ID = process.env.REACT_APP_KAKAO_API_KEY;
const REDIRECT_URI = "http://localhost:3000/api/user/kakao/callback";
const KAKAO_AUTH_URL = `https://kauth.kakao.com/oauth/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code`;
const kakaoLoginClick = () => {
console.log("clicked");
};
const { register } = useForm();
return (
<>
<InputContainer>
<Input
{...register("이메일")}
type="email"
placeholder="이메일을 입력하세요"
/>
<Input
{...register("비밀번호")}
type="password"
placeholder="비밀번호를 입력하세요"
/>
<Link to="/signup">
<h3>회원가입</h3>
</Link>
</InputContainer>
<a href={KAKAO_AUTH_URL}>
<LoginButton>
<img src={require("../img/kakao_logo.png")} alt="kakao_logo" />
</LoginButton>
</a>
</>
);
};
export default Login;
//Router.tsx
const CLIENT_ID = process.env.REACT_APP_KAKAO_API_KEY;
const REDIRECT_URI = "http://localhost:3000/api/user/kakao/callback";
const KAKAO_AUTH_URL = `https://kauth.kakao.com/oauth/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code`;
return (
<BrowserRouter>
<div className="App">
<Switch>
<Route exact path="/login">
<Login />
</Route>
<Route path="/api/user/kakao/callback">
<Test />
</Route>
</Switch>
</div>
</BrowserRouter>
//Test.tsx
const Test = () => {
return window.kakao.Auth.login({
scope: "profile, account_email",
success: function (res: any) {
console.log(res);
},
});
};
export default Test;
Test.tsx에서
Test.tsx:2 Uncaught TypeError: Cannot read properties of undefined (reading 'login')
at Test (Test.tsx:2:1)
at renderWithHooks (react-dom.development.js:14985:1)
at mountIndeterminateComponent (react-dom.development.js:17811:1)
at beginWork (react-dom.development.js:19049:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
at invokeGuardedCallback (react-dom.development.js:4056:1)
at beginWork$1 (react-dom.development.js:23964:1)
at performUnitOfWork (react-dom.development.js:22776:1)
at workLoopSync (react-dom.development.js:22707:1)
react-dom.development.js:20085 The above error occurred in the <Test> component:
at Test (http://localhost:3000/static/js/bundle.js:1062:28)
at Route (http://localhost:3000/static/js/bundle.js:44250:29)
at Switch (http://localhost:3000/static/js/bundle.js:44452:29)
at div
at Router (http://localhost:3000/static/js/bundle.js:43885:30)
at BrowserRouter (http://localhost:3000/static/js/bundle.js:43506:35)
at Router
at App
이렇게 뜨는데 구글링 해봐도 뭐가 문제인지 모르겠습니다…