import React, { ChangeEvent, FormEvent, useState } from "react"; import { Link, useLocation, useNavigate } from "react-router-dom"; import { catchErrors } from "../helpers"; import { SpinnerIcon } from "../icons"; import { useAuth } from "./auth.context"; // import { REST_API_KEY, REDIRECT_URI } from "../auth"; import { authApi } from "../apis"; import KakaoLoginImg from "../icons/kakao_login_medium_wide.png"; interface LocationState { state: { from: string }; } export const Login = () => { const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const [loginData, setLoginData] = useState({ email: "", password: "" }); const navigate = useNavigate(); const location = useLocation() as LocationState; const { login } = useAuth(); const from = location.state?.from || "/"; function handleChange(e: ChangeEvent) { const { name, value } = e.currentTarget; setLoginData({ ...loginData, [name]: value }); } async function handleSubmit(e: FormEvent) { e.preventDefault(); const { email, password } = loginData; try { setLoading(true); await login(email, password, () => navigate(from, { replace: true })); } catch (error) { setLoading(false); catchErrors(error, setError); } } const kakaoLogin = async () => { // const data = {REST_API_KEY:"", REDIRECT_URI:""} try { // DB에서 카카오 API키 받아온 후 전달 const data = await authApi.getOauthKeys("kakao"); console.log(data); window.location.href = `https://kauth.kakao.com/oauth/authorize?client_id=${data.REST_API_KEY}&redirect_uri=${data.REDIRECT_URI}&response_type=code`; } catch (error) { setLoading(false); catchErrors(error, setError); } }; return (
로그인
{error && (

{error}

)}
{loading && ( )}

회원이 아니십니까?

회원가입 →
); };