import React, { useState, useEffect } from 'react';
import { Link, Redirect } from 'react-router-dom';
import styled from 'styled-components';
import axios from 'axios';
import { Navbar, Nav, NavLink } from 'react-bootstrap';
const MENU = styled(Navbar)`
background-color: #7B031D;
a {
color : white;
}
`
function Menu() {
const [state, setState] = useState()
const [user, setUser] = useState({ role: "" })
const name = localStorage.getItem('name');
function logout() {
localStorage.clear();
alert("로그아웃 되었습니다.");
setState(true);
}
useEffect(() => {
acheck();
}, [])
function acheck() {
axios.get(`/users/${localStorage.getItem('_id')}`, {
headers: { authorization: localStorage.getItem('token') },
}).then(res => {
console.log(res.data)
if (res.data.role == "admin") {
setUser(res.data)
}
}).catch(err => {
alert(err.error)
});
}
if (state) return