Menu.js 1.15 KB
Newer Older
JeongYeonwoo's avatar
JeongYeonwoo committed
1
import React, { useState, useEffect } from 'react'
Choi Ga Young's avatar
Choi Ga Young committed
2
import { Navbar, Nav, Button } from 'react-bootstrap';
우지원's avatar
우지원 committed
3
import { Link } from 'react-router-dom';
4
import { handleLogout } from '../utils/auth';
JeongYeonwoo's avatar
JeongYeonwoo committed
5
import axios from 'axios'
Choi Ga Young's avatar
Choi Ga Young committed
6
7

function Menu() {
JeongYeonwoo's avatar
JeongYeonwoo committed
8
9
10
11
12
13
14
15
16
17
18
  const [username, setUsername] = useState('')

  async function getLoginedUser() { //email로 db에서 찾아오기 ㅇㅇㅇㅇㅇ
    const userid = localStorage.getItem('user')
    const response = await axios.post(`/users/${userid}`, { 'email': userid })
    setUsername(response.data.username)
  }

  useEffect(() => {
    getLoginedUser()
  }, [])
Choi Ga Young's avatar
Choi Ga Young committed
19
20
21
22

  return (
    <Navbar bg="dark" variant="dark">
      <Navbar.Brand href="/home">YDK Messenger</Navbar.Brand>
JeongYeonwoo's avatar
JeongYeonwoo committed
23
      <div className='ml-1 mr-2' style={{ color: 'white' }}>{username}  환영합니다</div>
Choi Ga Young's avatar
Choi Ga Young committed
24
25
26
27
28
      <Nav className="mr-auto">
        <Nav.Link href="/home">Home</Nav.Link>
        <Nav.Link href="/profile">Profile</Nav.Link>
        <Nav.Link href="/hello">Hello</Nav.Link>
      </Nav>
우지원's avatar
우지원 committed
29
30
31
      <Link to="./login">
        <Button onClick={() => handleLogout()} variant="light" className="ml-3">Logout</Button>
      </Link>
Choi Ga Young's avatar
Choi Ga Young committed
32
33
34
35
36
    </Navbar>
  )
}

export default Menu