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

a

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