정의왕

Complete Login/Register(without auth)

......@@ -6,9 +6,11 @@ import "./static/fonts/font.css";
import LandingPage from "./component/views/LandingPage/LandingPage";
function App () {
let isAuthorized = sessionStorage.getItem("isAuthorized"); //
return (
<Router>
<div>
{!isAuthorized ? <Redirect to="/login" /> : <Redirect to="/" />}
<Routes>
<Route exact path = "/" element={<LandingPage/>}/>
<Route exact path = "/login" element={<LoginPage/>}/>
......
import React, {useState} from "react";
import "../style/LoginPage.scss";
import Axios from 'axios'
import { Icon, Input } from "semantic-ui-react"
import { useNavigate } from "react-router-dom";
......@@ -19,8 +20,24 @@ function LoginPage(props) {
event.preventDefault();
console.log("ID", Id);
console.log("Password", Password);
};
Axios.post('/api/login',{
Id,
Password,
})
.then((res)=>{
if(res.status === 200){
alert("성공적으로 로그인하였습니다.")
navigate('/main')
}
}).catch((error) => {
if(error.response.data === 'idError'){
alert("존재하지 않는 아이디입니다.")
}
else if(error.response.data === 'pwError'){
alert("잘못된 비밀번호입니다.")
}
})
};
const goToRegister = () => {
navigate('/register');
}
......
......@@ -45,9 +45,9 @@ function RegisterPage(props) {
}
}).catch((error) => {
console.log(error.response)
alert("중복된 아이디입니다.")
})
}
},[Id, Password, Personality, PasswordCheck])
return (
<div id="Register">
......