Menu.js 1.5 KB
Newer Older
우지원's avatar
0113    
우지원 committed
1
// import axios from 'axios';
우지원's avatar
a    
우지원 committed
2
import { response } from 'express';
우지원's avatar
0113    
우지원 committed
3
import React, { useState, useEffect } from 'react';
Choi Ga Young's avatar
Choi Ga Young committed
4
import { Navbar, Nav, Button } from 'react-bootstrap';
우지원's avatar
우지원 committed
5
import { handleLogout, isAuthenticated } from '../utils/auth';
Choi Ga Young's avatar
Choi Ga Young committed
6

우지원's avatar
0113    
우지원 committed
7
8
9
10
11
// const INIT_USER = {
//   username: ''
// }


Choi Ga Young's avatar
Choi Ga Young committed
12
13
function Menu() {
  const userName = "정연우";
우지원's avatar
우지원 committed
14
  const user = isAuthenticated()
우지원's avatar
0113    
우지원 committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  // const [userName, setUsername] = useState(INIT_USER)

  // async function getLoginedUser() {
  //   const userId = localStorage.getItem('user')
  //   const response = await axios.get(`/users/${userId}`)
  //   setUsername(response.data)
  // }

  // useEffect((user) => {
  //   if (localStorage.getItem('user')) {
  //     getLoginedUser(user)
  //   }
  // }, [])

Choi Ga Young's avatar
Choi Ga Young committed
29
30
31
32

  return (
    <Navbar bg="dark" variant="dark">
      <Navbar.Brand href="/home">YDK Messenger</Navbar.Brand>
우지원's avatar
우지원 committed
33
34
35

      {user ?
        <>
우지원's avatar
0113    
우지원 committed
36
          <div className='ml-1 mr-2' style={{ color: 'white' }}>{response.data}  환영합니다</div>
우지원's avatar
우지원 committed
37
38
39
40
41
42
43
44
45
46
47
48
          <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>
          <Button className="ml-auto" onClick={() => handleLogout()} variant="light" className="ml-3">Logout</Button>
        </>
        : <Nav className="ml-auto">
          <Nav.Link href='/login'>로그인</Nav.Link>
          <Nav.Link href='/signup'>회원가입</Nav.Link>
        </Nav>}

Choi Ga Young's avatar
Choi Ga Young committed
49
50
51
52
53
    </Navbar>
  )
}

export default Menu