고병후

Remove error

{
"id": "3"
"id": 1
}
\ No newline at end of file
......
......@@ -4,6 +4,9 @@ const router = express.Router();
router.post('/',(req,res)=>{
console.log(req.body);
return res.status(200).json({
success: true
});
});
router.get('/',(req,res)=>{
......
export const LOGIN_USER = "login_user";
export const REGISTER_USER = "register_user";
\ No newline at end of file
import Axios from 'axios';
import { LOGIN_USER, REGISTER_USER } from './types';
export function loginUser(dataToSubmit) {
const request = Axios.post('/api/login', dataToSubmit)
.then( response => response.data )
return {
type: LOGIN_USER,
payload: request
}
}
export function registerUser(dataToSubmit) {
const request = Axios.post('/api/register', dataToSubmit)
.then( response => response.data )
return {
type: REGISTER_USER,
payload: request
}
}
\ No newline at end of file
import { combineReducers } from 'redux';
import user from './user_reducer';
const rootReducer = combineReducers({
user
})
export default rootReducer;
import {
LOGIN_USER, REGISTER_USER
} from '../_actions/types';
export default function (state = {}, action) {
switch (action.type) {
case LOGIN_USER:
return { ...state, loginSuccess: action.payload }
break;
case REGISTER_USER:
return {...state, register: action.payload}
break;
default:
return state;
}
}
\ No newline at end of file
......@@ -2,11 +2,8 @@ import React, {useState} from "react";
import "../style/LoginPage.scss";
import { Icon, Input } from "semantic-ui-react"
import { useNavigate } from "react-router-dom";
import {useDispatch} from "react-redux";
import { loginUser } from '../../../_actions/user_action'
function LoginPage(props) {
const dispatch = useDispatch();
const navigate = useNavigate();
const [Id, setId] = useState("");
......@@ -26,15 +23,7 @@ function LoginPage(props) {
email: Id,
password: Password
}
dispatch(loginUser(body))
.then(response => {
if (response.payload.loginSuccess) {
props.history.push('/main')
}
else{
alert('Error')
}
})
};
......
import React, {useState} from "react";
import "../style/RegisterPage.scss";
import { Button, Icon, Input } from "semantic-ui-react";
import {useDispatch} from "react-redux";
import { registerUser } from '../../../_actions/user_action'
import Axios from 'axios'
function RegisterPage(props) {
const dispatch = useDispatch();
function RegisterPage() {
const [Id, setId] = useState("");
const [Password, setPassword] = useState("");
const [PasswordCheck,setPasswordCheck] = useState("");
......@@ -37,14 +35,7 @@ function RegisterPage(props) {
password: Password,
personality: Personality
}
dispatch(registerUser(body))
.then(response => {
if (response.payload.success) {
props.history.push('/login')
} else {
alert('Failed to sign up')
}
})
}
return (
<div id="Register">
......
......@@ -4,19 +4,11 @@ import {Provider} from "react-redux";
import './index.css';
import App from './App';
import 'semantic-ui-css/semantic.min.css'
import {applyMiddleware, createStore} from "redux";
import promiseMiddleware from 'redux-promise-middleware'
import ReduxThunk from 'redux-thunk'
import Reducer from './_reducers';
const createStoreWithMiddleWare = applyMiddleware(promiseMiddleware, ReduxThunk)(createStore)
ReactDOM.render(
<Provider store={createStoreWithMiddleWare(Reducer,
window.__REDUX_DEVTOOLS_EXTENSION__ &&
window.__REDUX_DEVTOOLS_EXTENSION__()
)}>
<App />
</Provider>,
<App />,
document.getElementById('root')
);
......