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-14 17:06:15 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
422563e7bb03491b1995a00c127e41e6836dea83
422563e7
1 parent
5bee7d9d
/mypick 라우팅 및 '/api/auth' 인증 api 구현
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
14 deletions
client/src/App.js
client/src/pages/MypickPage.js
client/src/pages/SigninPage.js
server.js
client/src/App.js
View file @
422563e
...
...
@@ -4,6 +4,7 @@ import AboutPage from './pages/AboutPage';
import
MenuPage
from
'./pages/MenuPage'
;
import
SigninPage
from
'./pages/SigninPage'
;
import
SignupPage
from
'./pages/SignupPage'
;
import
MypickPage
from
'./pages/MypickPage'
;
import
{
BrowserRouter
as
Router
,
...
...
@@ -22,7 +23,7 @@ function App() {
<
Route
exact
path
=
"/menu"
component
=
{
MenuPage
}
/
>
<
Route
exact
path
=
"/signin"
component
=
{
SigninPage
}
/
>
<
Route
exact
path
=
"/signup"
component
=
{
SignupPage
}
/
>
{
/* mypick 라우팅 */
}
<
Route
exact
path
=
"/mypick"
component
=
{
MypickPage
}
/
>
<
/Switch
>
<
/
>
<
/Router
>
...
...
client/src/pages/MypickPage.js
0 → 100644
View file @
422563e
import
React
,
{
useState
}
from
'react'
import
NavBar
from
'../components/NavBar'
;
// auth로 로그인한 사용자일 때와 아닐때 판단해서 화면을 다르게
// 렌더링
const
MypickPage
=
()
=>
{
const
[
isLogin
,
setIsLogin
]
=
useState
(
false
);
return
(
<>
<
NavBar
/>
{
isLogin
?
<
h1
>
mypick
<
/h1> : <a>aaa</
a
>
}
<
/
>
)
}
export
default
MypickPage
;
client/src/pages/SigninPage.js
View file @
422563e
...
...
@@ -29,7 +29,7 @@ const SigninPage = (props) => {
});
if
(
response
.
message
===
"Token issue"
)
{
localStorage
.
setItem
(
"user
_token
"
,
JSON
.
stringify
(
response
.
token
));
localStorage
.
setItem
(
"user"
,
JSON
.
stringify
(
response
.
token
));
alert
(
'Login success'
);
props
.
history
.
push
(
'/'
);
}
else
if
(
response
.
message
===
"user does not exist"
){
...
...
server.js
View file @
422563e
...
...
@@ -33,10 +33,6 @@ connection.connect();
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
app
.
get
(
"/api/hello"
,
(
req
,
res
)
=>
{
res
.
send
(
"Hello skrrrr!"
);
});
// datas 전달
app
.
get
(
"/api/datas"
,
(
req
,
res
)
=>
{
iconv
.
extendNodeEncodings
();
...
...
@@ -68,14 +64,6 @@ app.post("/api/signup", (req, res) => {
});
});
// ????
// res.send({
// "code":200,
// "message": "success"
// })
// ????
// jwt_secret_key.value
// signin
app
.
post
(
"/api/signin"
,
(
req
,
res
)
=>
{
const
name
=
req
.
body
.
username
;
...
...
@@ -139,4 +127,35 @@ app.post("/api/signin", (req, res) => {
});
// ?? ???
app
.
get
(
'/api/auth'
,
(
req
,
res
)
=>
{
// ?? ??
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'
});
}
// ?? ??
catch
(
error
)
{
// ????? ??? ??
if
(
error
.
name
===
'TokenExpiredError'
)
{
return
res
.
status
(
419
).
json
({
code
:
419
,
message
:
'expired token'
});
}
// ??? ???? ???? ?? ??
return
res
.
status
(
401
).
json
({
code
:
401
,
message
:
'invalid token'
});
}
});
app
.
listen
(
port
,
()
=>
console
.
log
(
`Listening on port
${
port
}
`
));
...
...
Please
register
or
login
to post a comment