Commit 055db460 authored by 우지원's avatar 우지원
Browse files

a

parent dea888ad
......@@ -17,7 +17,7 @@ function Chat(props) {
}
async function getLoginedUser() { //email로 db에서 찾아오기 ㅇㅇㅇㅇㅇ
const userid = localStorage.getItem('user')
const userid = sessionStorage.getItem('user')
const response = await axios.post(`/users/${userid}`, { '_id': userid })
setUsername(response.data.username)
}
......
......@@ -8,19 +8,19 @@ function Menu() {
const [userName, setUsername] = useState('')
async function getLoginedUser() {
const userId = localStorage.getItem('user')
const response = await axios.get(`/users/${userId}`)
console.log(response.data.username)
const userid = sessionStorage.getItem('user')
const response = await axios.get(`/users/${userid}`, { '_id': userid })
console.log(response.data)
const resName = response.data.username
const resName = response.data
//const resName = JSON.stringify(response.data.username)
console.log(resName)
setUsername(resName)
}
console.log(userName)
console.log(userName.username)
useEffect((user) => {
if (localStorage.getItem('user')) {
if (sessionStorage.getItem('user')) {
getLoginedUser(user)
}
}, [])
......@@ -32,7 +32,7 @@ function Menu() {
{user ?
<>
<div className='ml-1 mr-2' style={{ color: 'white' }}>{userName} 환영합니다</div>
<div className='ml-1 mr-2' style={{ color: 'white' }}>{userName.username} 환영합니다</div>
<Nav className="mr-auto">
<Nav.Link href="/home">Home</Nav.Link>
<Nav.Link href="/profile">Profile</Nav.Link>
......
......@@ -27,7 +27,7 @@ function ProfilePage() {
async function getLoginedUser() { //email로 db에서 찾아오기 ㅇㅇㅇㅇㅇ
const userid = localStorage.getItem('user')
const userid = sessionStorage.getItem('user')
const response = await axios.post(`/users/${userid}`, { '_id': userid })
setUser(response.data)
}
......@@ -45,7 +45,7 @@ function ProfilePage() {
setUser({ ...user, 'nickname': e.target.value })
}
async function handleNicksave() {
const userid = localStorage.getItem('user')
const userid = sessionStorage.getItem('user')
await axios.put(`/users/${userid}`, user)
}
......@@ -82,7 +82,7 @@ function ProfilePage() {
}
}
useEffect(() => {
if (localStorage.getItem('user')) { //id뿐만아니라 토큰같은거를 확인 못하나 + 이런식으로 확인해도 되는것도 맞나
if (sessionStorage.getItem('user')) { //id뿐만아니라 토큰같은거를 확인 못하나 + 이런식으로 확인해도 되는것도 맞나
getLoginedUser()
}
else {
......
import axios from "axios"
//자동으로 localstorage에 login이 생성됨
//자동으로 sessionStorage에 login이 생성됨
export function handleLogin(userId) {
localStorage.setItem('user', userId)
sessionStorage.setItem('user', userId)
}
export async function handleLogout() {
localStorage.removeItem('user')
sessionStorage.removeItem('user')
await axios.get('/auth/logout')
//login페이지로 이동
window.location.href='/login'
......@@ -14,7 +14,7 @@ export async function handleLogout() {
//login이 됬는지 안됬는지 따질때 쓰임
export function isAuthenticated() {
const userId = localStorage.getItem('user')
const userId = sessionStorage.getItem('user')
if (userId) {
return userId
} else {
......
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