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 Nav1 from '../Components/MainNav';
import Nav2 from '../Components/SubNav';
......@@ -30,17 +30,18 @@ function Login() {
setValidated(true);
try {
setError('')
await axios.post('api/auth/login', user)
await axios.post('/api/auth/login', user)
handleLogin()
setSuccess(true)
} catch (error) {
catchErrors(error, setError)
console.log(error)
}
if (success) {
}if (success) {
return <Redirect to='/' />
}
}
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')))
// app.use('/', indexRouter);
app.use('/', kakaopayRoutes)
app.use('/api/users',userRouter)
app.use('/api/auth/login',authRouter)
app.use('/api/auth',authRouter)
app.use('/api/products', productRouter)
app.listen(config.port, () => {
......
......@@ -9,7 +9,7 @@ const login = async(req,res)=>{
try{
const user=await User.findOne({id}).select('+password')
if(!user){
return res.Status(404).send(`${id}가 존재하지 않습니다.`)
return res.status(404).send(`${id}가 존재하지 않습니다.`)
}
const passwordMatch= await bcrypt.compare(password, user.password)
......@@ -25,12 +25,17 @@ const login = async(req,res)=>{
})
res.send('로그인 되었습니다.')
}else{
res.Status(401).send('비밀번호가 일치하지 않습니다.')
res.status(401).send('비밀번호가 일치하지 않습니다.')
}
}catch(error){
console.log(error)
res.Status(500).send('로그인 실패. 다시 시도하세요.')
res.status(500).send('로그인 실패. 다시 시도하세요.')
}
}
// const logout =(req,res)=>{
// res.clearCookie('token')
// res.send('로그아웃 되었습니다.')
// }
export default {login}
\ No newline at end of file
......@@ -3,7 +3,10 @@ import authCtrl from '../controllers/auth.controller.js';
const router = express.Router()
router.route('/api/auth/login')
router.route('/login')
.post(authCtrl.login)
// router.route('/logout')
// .get(authCtrl.logout)
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