Login.js 655 Bytes
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";

import { dataForage } from "../utils/LocalForage";

const Login = () => {
  console.log("visit Login");

  const navigate = useNavigate();
  const login = async () => {
    if (true) {
      //login success
      await dataForage.setItem("session", true);

      navigate("/");
    }
  };

  useEffect(() => {
    async function render() {
      if (await dataForage.getItem("session")) navigate("/");
    }
    render();
  }, [navigate]);

  return (
    <div className="Login">
      <button onClick={login}>로그인</button>
    </div>
  );
};

export default Login;