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
bora-it
Commits
3aa0a668
Commit
3aa0a668
authored
Jul 27, 2021
by
seoyeon
Browse files
0727
parent
0804ee25
Changes
5
Hide whitespace changes
Inline
Side-by-side
client/src/apis/user.api.js
View file @
3aa0a668
import
axios
from
"
axios
"
;
const
getUser
=
async
(
payload
)
=>
{
const
{
data
}
=
await
axios
.
ge
t
(
"
/api/
u
ser
"
,
payload
);
const
{
data
}
=
await
axios
.
pos
t
(
"
/api/
getU
ser
"
,
payload
);
return
data
;
};
...
...
client/src/components/Home/HomeProfile.js
View file @
3aa0a668
...
...
@@ -2,8 +2,10 @@ import { Link } from "react-router-dom";
import
{
useState
,
useEffect
}
from
"
react
"
;
import
userApi
from
"
../../apis/user.api
"
;
const
userprofile
=
localStorage
.
getItem
(
"
user
"
);
console
.
log
(
userprofile
)
const
INIT_USER
=
{
id
:
''
,
id
:
userprofile
,
name
:
''
,
img
:
''
,
}
...
...
@@ -11,14 +13,13 @@ const INIT_USER = {
const
HomeProfile
=
()
=>
{
const
[
user
,
setUser
]
=
useState
(
INIT_USER
)
const
id
=
localStorage
.
getItem
(
'
user
'
);
async
function
getUser
(
id
)
{
async
function
getSetUser
(
userID
)
{
try
{
// `/users/${userId}`랑 userId랑 같은지 확인
const
User
=
await
userApi
.
user
(
id
)
console
.
log
(
User
)
setUser
(
User
.
data
)
console
.
log
(
'
userID
'
,
userID
)
const
data
=
await
userApi
.
getUser
({
id
:
userID
})
console
.
log
(
data
)
setUser
(
data
)
console
.
log
(
user
)
}
catch
(
error
)
{
// catchErrors(error, setError)
...
...
@@ -26,11 +27,12 @@ const HomeProfile = () => {
}
useEffect
(()
=>
{
getUser
(
id
)
},
[
id
])
console
.
log
(
'
예에에에에ㅔ에에
'
)
getSetUser
(
userprofile
)
},
[
userprofile
])
return
(
<
Link
to
=
{
`/profile/
${
id
}
`
}
className
=
"
text-decoration-none text-dark
"
>
<
Link
to
=
{
`/profile/
${
user
}
`
}
className
=
"
text-decoration-none text-dark
"
>
<
form
className
=
"
flex-column align-items-center justify-content-center m-2
"
>
<
div
className
=
"
d-flex justify-content-center
"
>
<
img
...
...
client/src/context/auth.js
View file @
3aa0a668
...
...
@@ -6,7 +6,7 @@ export function handleLogin(userId) {
export
async
function
handleLogout
()
{
alert
(
"
로그아웃되었습니다.
"
)
localStorage
.
removeItem
(
'
loginStatus
'
)
localStorage
.
removeItem
(
"
user
"
)
await
axios
.
get
(
'
/api/auth/logout
'
)
window
.
location
.
href
=
'
/
'
}
...
...
controllers/user.controller.js
View file @
3aa0a668
...
...
@@ -4,9 +4,12 @@ import config from '../config/app.config.js'
import
isLength
from
'
validator/lib/isLength.js
'
import
bcrypt
from
"
bcryptjs
"
;
const
user
=
async
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
)
const
user
=
await
User
.
findAll
({
where
:
{
id
:
req
.
body
}
});
const
getUser
=
async
(
req
,
res
)
=>
{
console
.
log
(
'
유저가져왔다아아아ㅏㅇ:
'
,
req
.
body
)
console
.
log
(
'
id:
'
,
req
.
body
.
id
)
const
id
=
req
.
body
.
id
const
user
=
await
User
.
findOne
({
where
:
{
id
:
id
}
});
console
.
log
(
'
user:
'
,
user
)
req
.
json
(
user
)
};
...
...
@@ -85,7 +88,7 @@ const logout = (req, res) => {
}
export
default
{
u
ser
,
getU
ser
,
login
,
signup
,
logout
,
...
...
routes/user.route.js
View file @
3aa0a668
...
...
@@ -3,7 +3,7 @@ import userCtrl from "../controllers/user.controller.js";
const
router
=
express
.
Router
();
router
.
route
(
"
/getUser
"
).
ge
t
(
userCtrl
.
u
ser
);
router
.
route
(
"
/getUser
"
).
pos
t
(
userCtrl
.
getU
ser
);
router
.
route
(
"
/login
"
).
post
(
userCtrl
.
login
);
router
.
route
(
"
/signup
"
).
post
(
userCtrl
.
signup
);
...
...
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