Commit d3301a50 authored by 이재연's avatar 이재연
Browse files

로그아웃 버튼 수정중

parent 42ab4e72
import React, { useState, useEffect, useRef } from 'react';
import { Navbar, Nav } from 'react-bootstrap';
import { Navbar, Nav, Row } from 'react-bootstrap';
import logo from '../footprint.svg';
import cart from '../cart.svg';
import option from '../option.svg';
import { handleLogout, isAuthenticated } from '../utils/auth'
function MainNav() {
function handleClick() {
alert('로그아웃이 완료되었습니다.')
window.location.href="/home"
}
const user = isAuthenticated()
return (
<Navbar sticky="top" style={{ background: "#CDC5C2" }}>
......@@ -16,13 +14,17 @@ function MainNav() {
<img src={logo} width="24" height="24" />
{' '}KU#
</Navbar.Brand>
<Nav className="justify-content-end">
<Nav.Link className="text-light" href="/login">Login</Nav.Link>
<Nav.Link className="text-light" href="/signup">Signup</Nav.Link>
<Nav>
{user ? <Nav.Link className="text-light" onClick={() => handleLogout()}>Logout</Nav.Link>
: (
<>
<Nav.Link className="text-light" href='/login'>Login</Nav.Link>
<Nav.Link className="text-light" href='/signup'>Sign Up</Nav.Link>
</>
)}
<Nav.Link href="/shoppingcart">
<img src={cart} width="30" height="30" />
</Nav.Link>
<Nav.Link className="text-light" onClick={() => handleClick()}>Logout</Nav.Link>
<Nav.Link href="/admin">
<img src={option} width="30" height="30" />
</Nav.Link>
......
......@@ -20,6 +20,11 @@ function Login() {
const [error, setError] = useState('')
const [success, setSuccess] = useState(false)
function handleChange(event) {
const { name, value } = event.target
setUser({ ...user, [name]: value })
}
async function handleSubmit(event) {
event.preventDefault()
const form = event.currentTarget;
......@@ -34,19 +39,14 @@ function Login() {
handleLogin()
setSuccess(true)
} catch (error) {
catchErrors(error, setError)
console.log(error)
}
}if (success) {
return <Redirect to='/' />
}
function handleChange(event) {
const { name, value } = event.target
setUser({ ...user, [name]: value })
if (success) {
alert('로그인 되었습니다.')
return <Redirect to='/' />
}
......@@ -54,8 +54,7 @@ function Login() {
return (
<div>
<Nav1 />
<Nav2 />
<Container className="my-5">
<Row className="justify-content-center">
<Col md={5} xs={10} className="border" style={{ background: '#F7F3F3' }}>
......
// 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
......@@ -30,17 +30,18 @@ function ProductsList() {
<MainNav />
<SubNav />
<Container>
<Row className="justify-content-center mx-0 my-4">
<Col sm={10}>
<h1 style={{ fontSize: "3rem" }}>OUTER</h1>
<Row >
<Col sm={10} xs={12}>
<h1 style={{ fontSize: "3rem" }} className="text-center">OUTER</h1>
<div>{sub.map((ele) => (
<Button className="m-1">{ele}</Button>
<Button className="justify-content-center m-1">{ele}</Button>
))}</div>
</Col>
</Row>
<Row className="justify-content-between mx-0 my-5">
<Form as={Row} onSubmit={handleSubmit} className="justify-content-end mx-0">
<Dropdown>
<Dropdown.Toggle>정렬</Dropdown.Toggle>
<Dropdown.Toggle className="mx-2">정렬</Dropdown.Toggle>
<Dropdown.Menu>
<Dropdown.Item>인기상품</Dropdown.Item>
<Dropdown.Item>신상품</Dropdown.Item>
......@@ -48,15 +49,13 @@ function ProductsList() {
<Dropdown.Item>높은가격</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
<Form as={Row} onSubmit={handleSubmit} className="justify-content-end mx-0">
<FormControl type="text" placeholder="Search" style={{ width: "13rem" }} />
<Button type="submit" className="search px-2">
<Button type="submit" className="search px-2 mb-1 ">
<img src={search} width="20" height="20" />
</Button>
<Button sm={2} xs={6} type="button" href="/regist" className="ml-1">상품 등록</Button>
</Form>
</Row>
<Row className="justify-content-start m-5">
<Row md={8} sm={12} className="justify-content-start m-2">
<Card className="mt-5" style={{ width: "18rem", margin: "auto" }}>
<Card.Img variant="top" src="https://img.sonyunara.com/files/goods/67460/1607053816_0.jpg" style={{ objectFit: "contain", height: "22rem" }} />
<Card.Body>
......
......@@ -7,4 +7,14 @@ export function handleLogin(){
export async function handleLogout(){
localStorage.removeItem('loginStatus')
await axios.get('/api/auth/logout')
window.location.href='/'
}
export function isAuthenticated(){
const userId= localStorage.getItem('loginStatus')
if(userId){
return userId
} else{
return false
}
}
\ No newline at end of file
......@@ -33,9 +33,9 @@ const login = async(req,res)=>{
}
}
// const logout =(req,res)=>{
// res.clearCookie('token')
// res.send('로그아웃 되었습니다.')
// }
const logout =(req,res)=>{
res.clearCookie('token')
res.send('로그아웃 되었습니다.')
}
export default {login}
\ No newline at end of file
export default {login, logout}
\ No newline at end of file
......@@ -6,7 +6,7 @@ const router = express.Router()
router.route('/login')
.post(authCtrl.login)
// router.route('/logout')
// .get(authCtrl.logout)
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