Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정성훈
/
MEALKHU
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
swa07016
2020-06-21 00:07:22 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1d0828e53356f860aa5009978d71b761330689f6
1d0828e5
1 parent
59835b4a
token 기반 mypick username set
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
19 additions
and
13 deletions
client/package-lock.json
client/package.json
client/src/components/UserCards.js
client/src/pages/MenuPage.js
client/src/pages/MypickPage.js
package-lock.json
package.json
server.js
client/package-lock.json
View file @
1d0828e
This diff is collapsed. Click to expand it.
client/package.json
View file @
1d0828e
...
...
@@ -14,7 +14,6 @@
"axios"
:
"^0.19.2"
,
"bootstrap"
:
"^4.5.0"
,
"http-proxy-middleware"
:
"^1.0.4"
,
"mdbreact"
:
"^4.27.0"
,
"react"
:
"^16.13.1"
,
"react-app-polyfill"
:
"^1.0.6"
,
"react-cookies"
:
"^0.1.1"
,
...
...
client/src/components/UserCards.js
View file @
1d0828e
...
...
@@ -72,13 +72,14 @@ const UserCards = (props) => {
setDatas
(
result
.
data
);
};
fetchData
();
setUsername
(
cookie
.
load
(
'username'
));
setUsername
(
props
.
username
);
// setUsername(cookie.load('username'));
},
[
username
]);
const
LogoutHandler
=
(
e
)
=>
{
e
.
preventDefault
();
localStorage
.
removeItem
(
'user'
);
cookie
.
remove
(
'username'
);
//
cookie.remove('username');
props
.
isLogin
(
false
);
return
;
}
...
...
client/src/pages/MenuPage.js
View file @
1d0828e
...
...
@@ -3,9 +3,6 @@ import NavBar from '../components/NavBar';
import
MealCard
from
'../components/MealCard'
;
import
{
CustomInput
}
from
'reactstrap'
;
import
{
Container
,
Row
,
Col
}
from
"reactstrap"
;
import
{
Card
,
CardText
,
CardBody
,
CardTitle
,
}
from
"reactstrap"
;
import
axios
from
'axios'
;
import
Loading
from
'../components/Loading'
;
...
...
@@ -190,9 +187,6 @@ const MenuPage = (props) => {
<
/Container>
)
:
<
Loading
value
=
"Loading.."
/>
}
<
/
>
);
}
...
...
client/src/pages/MypickPage.js
View file @
1d0828e
...
...
@@ -9,6 +9,7 @@ import { Container } from 'reactstrap';
const
MypickPage
=
()
=>
{
const
[
isLogin
,
setIsLogin
]
=
useState
(
false
);
const
[
userName
,
setUserName
]
=
useState
(
''
);
const
authApi
=
()
=>
{
const
user
=
JSON
.
parse
(
localStorage
.
getItem
(
'user'
));
return
fetch
(
'/api/auth'
,
{
...
...
@@ -21,7 +22,7 @@ const MypickPage = () => {
.
then
(
result
=>
{
if
(
result
.
message
===
'valid token'
)
{
setIsLogin
(
true
);
setUserName
(
result
.
username
);
}
else
if
(
result
.
message
===
'expired token'
)
{
// alert('토큰이 만료되었습니다. 로그인 해주세요.');
setIsLogin
(
false
);
...
...
@@ -42,7 +43,7 @@ const MypickPage = () => {
{
isLogin
?
(
<>
<
UserCards
isLogin
=
{
setIsLogin
}
/
>
<
UserCards
username
=
{
userName
}
isLogin
=
{
setIsLogin
}
/
>
<
/>
)
:
(
<>
...
...
package-lock.json
View file @
1d0828e
...
...
@@ -601,6 +601,11 @@
"safe-buffer"
:
"^5.0.1"
}
},
"jwt-decode"
:
{
"version"
:
"2.2.0"
,
"resolved"
:
"https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz"
,
"integrity"
:
"sha1-fYa9VmefWM5qhHBKZX3TkruoGnk="
},
"locate-path"
:
{
"version"
:
"3.0.0"
,
"resolved"
:
"https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz"
,
...
...
package.json
View file @
1d0828e
...
...
@@ -21,6 +21,7 @@
"express"
:
"^4.17.1"
,
"iconv-lite"
:
"^0.5.1"
,
"jsonwebtoken"
:
"^8.5.1"
,
"jwt-decode"
:
"^2.2.0"
,
"mysql"
:
"^2.18.1"
}
}
...
...
server.js
View file @
1d0828e
...
...
@@ -4,6 +4,7 @@ const fs = require("fs");
const
mysql
=
require
(
"mysql"
);
const
iconv
=
require
(
"iconv-lite"
);
const
jwt
=
require
(
"jsonwebtoken"
);
const
jwt_decode
=
require
(
'jwt-decode'
);
const
bcrypt
=
require
(
"bcrypt"
);
const
saltRounds
=
10
;
...
...
@@ -144,13 +145,17 @@ app.post("/api/signin", (req, res) => {
// ?? ???
app
.
get
(
'/api/auth'
,
(
req
,
res
)
=>
{
// ?? ??
const
user
=
jwt_decode
(
req
.
headers
.
authorization
);
console
.
log
(
user
.
name
);
try
{
// ?? ??? ??? ??(req.headers.authorization)? ???? ???? ?? ??
req
.
decoded
=
jwt
.
verify
(
req
.
headers
.
authorization
,
jwt_secret_key
.
value
);
return
res
.
status
(
200
).
json
({
code
:
200
,
message
:
'valid token'
message
:
'valid token'
,
username
:
user
.
name
});
}
...
...
Please
register
or
login
to post a comment