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-15 01:43:20 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
20a2ce4de78a69a9e36798bdf29497971186d0aa
20a2ce4d
1 parent
312714cf
Logout 구현
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
11 deletions
client/package-lock.json
client/package.json
client/src/components/UserCards.js
client/src/pages/MypickPage.js
client/src/pages/SigninPage.js
server.js
client/package-lock.json
View file @
20a2ce4
...
...
@@ -11028,6 +11028,22 @@
"whatwg-fetch"
:
"^3.0.0"
}
},
"react-cookies"
:
{
"version"
:
"0.1.1"
,
"resolved"
:
"https://registry.npmjs.org/react-cookies/-/react-cookies-0.1.1.tgz"
,
"integrity"
:
"sha512-PP75kJ4vtoHuuTdq0TAD3RmlAv7vuDQh9fkC4oDlhntgs9vX1DmREomO0Y1mcQKR9nMZ6/zxoflaMJ3MAmF5KQ=="
,
"requires"
:
{
"cookie"
:
"^0.3.1"
,
"object-assign"
:
"^4.1.1"
},
"dependencies"
:
{
"cookie"
:
{
"version"
:
"0.3.1"
,
"resolved"
:
"https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz"
,
"integrity"
:
"sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s="
}
}
},
"react-dev-utils"
:
{
"version"
:
"10.2.1"
,
"resolved"
:
"https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-10.2.1.tgz"
,
...
...
client/package.json
View file @
20a2ce4
...
...
@@ -16,6 +16,7 @@
"http-proxy-middleware"
:
"^1.0.4"
,
"react"
:
"^16.13.1"
,
"react-app-polyfill"
:
"^1.0.6"
,
"react-cookies"
:
"^0.1.1"
,
"react-dom"
:
"^16.13.1"
,
"react-router-dom"
:
"^5.2.0"
,
"react-scripts"
:
"3.4.1"
,
...
...
client/src/components/UserCards.js
View file @
20a2ce4
import
React
,
{
useState
,
useEffect
}
from
'react'
;
import
{
Container
,
Row
,
Col
}
from
'reactstrap'
;
import
{
Container
,
Row
,
Col
,
Button
}
from
'reactstrap'
;
import
cookie
from
'react-cookies'
;
import
axios
from
'axios'
;
import
MealCard
from
'../components/MealCard'
;
const
UserCards
=
()
=>
{
const
UserCards
=
(
props
)
=>
{
const
[
datas
,
setDatas
]
=
useState
([]);
const
[
username
,
setUsername
]
=
useState
(
'User'
);
const
[
picks
,
setPicks
]
=
useState
([{
"id"
:
"1"
,
"name"
:
"#신슨즈(#Shinsons)"
,
...
...
@@ -70,15 +72,22 @@ const UserCards = () => {
setDatas
(
result
.
data
);
};
fetchData
();
setUsername
(
cookie
.
load
(
'username'
));
},
[
username
]);
},
[]);
const
LogoutHandler
=
(
e
)
=>
{
e
.
preventDefault
();
localStorage
.
removeItem
(
'user'
);
cookie
.
remove
(
'username'
);
props
.
isLogin
(
false
);
return
;
}
return
(
<>
<
h1
style
=
{{
'paddingTop'
:
'3rem'
}}
className
=
"text-center"
>
<
span
className
=
"font-weight-bold"
>
User
's Pick</span>
<
div
className
=
"font-weight-bold"
>
{
username
}
's Pick</div>
<Button onClick={LogoutHandler} color="link" className="float-right"><h4>Logout</h4></Button>
</h1>
<br/>
<hr className="my-2" />
...
...
client/src/pages/MypickPage.js
View file @
20a2ce4
import
React
,
{
useState
,
useEffect
}
from
'react'
import
React
,
{
useState
,
useEffect
}
from
'react'
;
import
NavBar
from
'../components/NavBar'
;
import
LoginLink
from
'../components/LoginLink'
;
import
UserCards
from
'../components/UserCards'
;
...
...
@@ -9,7 +9,6 @@ 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'
,
{
...
...
@@ -43,8 +42,7 @@ const MypickPage = () => {
{
isLogin
?
(
<>
<
UserCards
/>
<
UserCards
isLogin
=
{
setIsLogin
}
/
>
<
/>
)
:
(
<>
...
...
client/src/pages/SigninPage.js
View file @
20a2ce4
import
React
,
{
useState
}
from
'react'
;
import
cookie
from
'react-cookies'
import
{
Button
,
Form
,
FormGroup
,
Label
,
Input
}
from
'reactstrap'
;
import
{
FacebookLoginButton
}
from
'react-social-login-buttons'
;
...
...
@@ -30,6 +31,11 @@ const SigninPage = (props) => {
if
(
response
.
message
===
"Token issue"
)
{
localStorage
.
setItem
(
"user"
,
JSON
.
stringify
(
response
.
token
));
const
expires
=
new
Date
()
expires
.
setDate
(
expires
.
getDate
()
+
60
)
cookie
.
save
(
'username'
,
response
.
username
,
{
expires
})
alert
(
'Login success'
);
props
.
history
.
push
(
'/mypick'
);
}
else
if
(
response
.
message
===
"user does not exist"
){
...
...
server.js
View file @
20a2ce4
...
...
@@ -97,12 +97,16 @@ app.post("/api/signin", (req, res) => {
issuer
:
"admin"
,
}
);
return
res
.
json
({
code
:
200
,
message
:
'Token issue'
,
token
,
username
:
name
});
}
catch
(
error
)
{
console
.
error
(
error
);
...
...
Please
register
or
login
to post a comment