Commit 418d3466 authored by 이재연's avatar 이재연
Browse files

로그인수정중

parent 42b6aaf5
import React, { useState, useEffect, useRef } from 'react'; import React, { useState } from 'react';
import { Link, Redirect } from 'react-router-dom'; import { Link, Redirect } from 'react-router-dom';
import Nav1 from '../Components/MainNav'; import Nav1 from '../Components/MainNav';
import Nav2 from '../Components/SubNav'; import Nav2 from '../Components/SubNav';
...@@ -30,17 +30,18 @@ function Login() { ...@@ -30,17 +30,18 @@ function Login() {
setValidated(true); setValidated(true);
try { try {
setError('') setError('')
await axios.post('api/auth/login', user) await axios.post('/api/auth/login', user)
handleLogin() handleLogin()
setSuccess(true) setSuccess(true)
} catch (error) { } catch (error) {
catchErrors(error, setError) catchErrors(error, setError)
console.log(error)
} }
if (success) {
}if (success) {
return <Redirect to='/' /> return <Redirect to='/' />
} }
}
function handleChange(event) { function handleChange(event) {
......
// import { Button } from 'bootstrap'
// import React from 'react'
// import { handleLogout } from '../utils/auth'
// function logout() {
// return (
// <div>
// <Button onClick={()=>handleLogout()}>Logout</Button>
// </div>
// )
// }
// export default logout
import React from 'react'
import {withRouter} from 'react-router-dom'
function LogoutButton({logout,history}){
const handleClick = () =>{
logout()
history.push("/")
}
return <button onClick={handleClick}>Logout</button>
}
export default withRouter(LogoutButton)
\ No newline at end of file
...@@ -23,7 +23,7 @@ app.use(express.static(path.join(process.cwd(), 'dist'))) ...@@ -23,7 +23,7 @@ app.use(express.static(path.join(process.cwd(), 'dist')))
// app.use('/', indexRouter); // app.use('/', indexRouter);
app.use('/', kakaopayRoutes) app.use('/', kakaopayRoutes)
app.use('/api/users',userRouter) app.use('/api/users',userRouter)
app.use('/api/auth/login',authRouter) app.use('/api/auth',authRouter)
app.use('/api/products', productRouter) app.use('/api/products', productRouter)
app.listen(config.port, () => { app.listen(config.port, () => {
......
...@@ -9,7 +9,7 @@ const login = async(req,res)=>{ ...@@ -9,7 +9,7 @@ const login = async(req,res)=>{
try{ try{
const user=await User.findOne({id}).select('+password') const user=await User.findOne({id}).select('+password')
if(!user){ if(!user){
return res.Status(404).send(`${id}가 존재하지 않습니다.`) return res.status(404).send(`${id}가 존재하지 않습니다.`)
} }
const passwordMatch= await bcrypt.compare(password, user.password) const passwordMatch= await bcrypt.compare(password, user.password)
...@@ -25,12 +25,17 @@ const login = async(req,res)=>{ ...@@ -25,12 +25,17 @@ const login = async(req,res)=>{
}) })
res.send('로그인 되었습니다.') res.send('로그인 되었습니다.')
}else{ }else{
res.Status(401).send('비밀번호가 일치하지 않습니다.') res.status(401).send('비밀번호가 일치하지 않습니다.')
} }
}catch(error){ }catch(error){
console.log(error) console.log(error)
res.Status(500).send('로그인 실패. 다시 시도하세요.') res.status(500).send('로그인 실패. 다시 시도하세요.')
} }
} }
// const logout =(req,res)=>{
// res.clearCookie('token')
// res.send('로그아웃 되었습니다.')
// }
export default {login} export default {login}
\ No newline at end of file
...@@ -3,7 +3,10 @@ import authCtrl from '../controllers/auth.controller.js'; ...@@ -3,7 +3,10 @@ import authCtrl from '../controllers/auth.controller.js';
const router = express.Router() const router = express.Router()
router.route('/api/auth/login') router.route('/login')
.post(authCtrl.login) .post(authCtrl.login)
// router.route('/logout')
// .get(authCtrl.logout)
export default router export default router
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment