Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
messenger
Commits
055db460
Commit
055db460
authored
Jan 15, 2021
by
우지원
Browse files
a
parent
dea888ad
Changes
4
Hide whitespace changes
Inline
Side-by-side
client/src/Components/Chat.js
View file @
055db460
...
@@ -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
=
local
Storage
.
getItem
(
'
user
'
)
const
userid
=
session
Storage
.
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
)
}
}
...
...
client/src/Components/Menu.js
View file @
055db460
...
@@ -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
user
I
d
=
local
Storage
.
getItem
(
'
user
'
)
const
user
i
d
=
session
Storage
.
getItem
(
'
user
'
)
const
response
=
await
axios
.
get
(
`/users/
${
user
I
d
}
`
)
const
response
=
await
axios
.
get
(
`/users/
${
user
i
d
}
`
,
{
'
_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
(
local
Storage
.
getItem
(
'
user
'
))
{
if
(
session
Storage
.
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
>
...
...
client/src/Pages/ProfilePage.js
View file @
055db460
...
@@ -27,7 +27,7 @@ function ProfilePage() {
...
@@ -27,7 +27,7 @@ function ProfilePage() {
async
function
getLoginedUser
()
{
//email로 db에서 찾아오기 ㅇㅇㅇㅇㅇ
async
function
getLoginedUser
()
{
//email로 db에서 찾아오기 ㅇㅇㅇㅇㅇ
const
userid
=
local
Storage
.
getItem
(
'
user
'
)
const
userid
=
session
Storage
.
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
=
local
Storage
.
getItem
(
'
user
'
)
const
userid
=
session
Storage
.
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
(
local
Storage
.
getItem
(
'
user
'
))
{
//id뿐만아니라 토큰같은거를 확인 못하나 + 이런식으로 확인해도 되는것도 맞나
if
(
session
Storage
.
getItem
(
'
user
'
))
{
//id뿐만아니라 토큰같은거를 확인 못하나 + 이런식으로 확인해도 되는것도 맞나
getLoginedUser
()
getLoginedUser
()
}
}
else
{
else
{
...
...
client/src/utils/auth.js
View file @
055db460
import
axios
from
"
axios
"
import
axios
from
"
axios
"
//자동으로
locals
torage에 login이 생성됨
//자동으로
sessionS
torage에 login이 생성됨
export
function
handleLogin
(
userId
)
{
export
function
handleLogin
(
userId
)
{
local
Storage
.
setItem
(
'
user
'
,
userId
)
session
Storage
.
setItem
(
'
user
'
,
userId
)
}
}
export
async
function
handleLogout
()
{
export
async
function
handleLogout
()
{
local
Storage
.
removeItem
(
'
user
'
)
session
Storage
.
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
=
local
Storage
.
getItem
(
'
user
'
)
const
userId
=
session
Storage
.
getItem
(
'
user
'
)
if
(
userId
)
{
if
(
userId
)
{
return
userId
return
userId
}
else
{
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment