Showing
6 changed files
with
44 additions
and
10 deletions
... | @@ -11028,6 +11028,22 @@ | ... | @@ -11028,6 +11028,22 @@ |
11028 | "whatwg-fetch": "^3.0.0" | 11028 | "whatwg-fetch": "^3.0.0" |
11029 | } | 11029 | } |
11030 | }, | 11030 | }, |
11031 | + "react-cookies": { | ||
11032 | + "version": "0.1.1", | ||
11033 | + "resolved": "https://registry.npmjs.org/react-cookies/-/react-cookies-0.1.1.tgz", | ||
11034 | + "integrity": "sha512-PP75kJ4vtoHuuTdq0TAD3RmlAv7vuDQh9fkC4oDlhntgs9vX1DmREomO0Y1mcQKR9nMZ6/zxoflaMJ3MAmF5KQ==", | ||
11035 | + "requires": { | ||
11036 | + "cookie": "^0.3.1", | ||
11037 | + "object-assign": "^4.1.1" | ||
11038 | + }, | ||
11039 | + "dependencies": { | ||
11040 | + "cookie": { | ||
11041 | + "version": "0.3.1", | ||
11042 | + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", | ||
11043 | + "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" | ||
11044 | + } | ||
11045 | + } | ||
11046 | + }, | ||
11031 | "react-dev-utils": { | 11047 | "react-dev-utils": { |
11032 | "version": "10.2.1", | 11048 | "version": "10.2.1", |
11033 | "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-10.2.1.tgz", | 11049 | "resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-10.2.1.tgz", | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | "http-proxy-middleware": "^1.0.4", | 16 | "http-proxy-middleware": "^1.0.4", |
17 | "react": "^16.13.1", | 17 | "react": "^16.13.1", |
18 | "react-app-polyfill": "^1.0.6", | 18 | "react-app-polyfill": "^1.0.6", |
19 | + "react-cookies": "^0.1.1", | ||
19 | "react-dom": "^16.13.1", | 20 | "react-dom": "^16.13.1", |
20 | "react-router-dom": "^5.2.0", | 21 | "react-router-dom": "^5.2.0", |
21 | "react-scripts": "3.4.1", | 22 | "react-scripts": "3.4.1", | ... | ... |
1 | import React, { useState, useEffect } from 'react'; | 1 | import React, { useState, useEffect } from 'react'; |
2 | -import { Container, Row, Col } from 'reactstrap'; | 2 | +import { Container, Row, Col, Button } from 'reactstrap'; |
3 | +import cookie from 'react-cookies'; | ||
3 | import axios from 'axios'; | 4 | import axios from 'axios'; |
4 | import MealCard from '../components/MealCard'; | 5 | import MealCard from '../components/MealCard'; |
5 | 6 | ||
6 | -const UserCards = () => { | 7 | +const UserCards = (props) => { |
7 | const [datas, setDatas] = useState([]); | 8 | const [datas, setDatas] = useState([]); |
9 | + const [username, setUsername] = useState('User'); | ||
8 | const [picks, setPicks] = useState([{ | 10 | const [picks, setPicks] = useState([{ |
9 | "id": "1", | 11 | "id": "1", |
10 | "name": "#신슨즈(#Shinsons)", | 12 | "name": "#신슨즈(#Shinsons)", |
... | @@ -70,15 +72,22 @@ const UserCards = () => { | ... | @@ -70,15 +72,22 @@ const UserCards = () => { |
70 | setDatas(result.data); | 72 | setDatas(result.data); |
71 | }; | 73 | }; |
72 | fetchData(); | 74 | fetchData(); |
75 | + setUsername(cookie.load('username')); | ||
76 | + }, [username]); | ||
73 | 77 | ||
74 | - }, []); | 78 | + const LogoutHandler = (e) => { |
75 | - | 79 | + e.preventDefault(); |
76 | - | 80 | + localStorage.removeItem('user'); |
81 | + cookie.remove('username'); | ||
82 | + props.isLogin(false); | ||
83 | + return ; | ||
84 | + } | ||
77 | 85 | ||
78 | return ( | 86 | return ( |
79 | <> | 87 | <> |
80 | <h1 style={{'paddingTop':'3rem'}} className="text-center"> | 88 | <h1 style={{'paddingTop':'3rem'}} className="text-center"> |
81 | - <span className="font-weight-bold">User's Pick</span> | 89 | + <div className="font-weight-bold">{username}'s Pick</div> |
90 | + <Button onClick={LogoutHandler} color="link" className="float-right"><h4>Logout</h4></Button> | ||
82 | </h1> | 91 | </h1> |
83 | <br/> | 92 | <br/> |
84 | <hr className="my-2" /> | 93 | <hr className="my-2" /> | ... | ... |
1 | -import React, { useState, useEffect } from 'react' | 1 | +import React, { useState, useEffect } from 'react'; |
2 | import NavBar from '../components/NavBar'; | 2 | import NavBar from '../components/NavBar'; |
3 | import LoginLink from '../components/LoginLink'; | 3 | import LoginLink from '../components/LoginLink'; |
4 | import UserCards from '../components/UserCards'; | 4 | import UserCards from '../components/UserCards'; |
... | @@ -9,7 +9,6 @@ import { Container } from 'reactstrap'; | ... | @@ -9,7 +9,6 @@ import { Container } from 'reactstrap'; |
9 | 9 | ||
10 | const MypickPage = () => { | 10 | const MypickPage = () => { |
11 | const [isLogin, setIsLogin] = useState(false); | 11 | const [isLogin, setIsLogin] = useState(false); |
12 | - const [username, setUsername] = useState(''); | ||
13 | const authApi = () => { | 12 | const authApi = () => { |
14 | const user = JSON.parse(localStorage.getItem('user')); | 13 | const user = JSON.parse(localStorage.getItem('user')); |
15 | return fetch('/api/auth', { | 14 | return fetch('/api/auth', { |
... | @@ -43,8 +42,7 @@ const MypickPage = () => { | ... | @@ -43,8 +42,7 @@ const MypickPage = () => { |
43 | { | 42 | { |
44 | isLogin ? | 43 | isLogin ? |
45 | (<> | 44 | (<> |
46 | - | 45 | + <UserCards isLogin={setIsLogin}/> |
47 | - <UserCards/> | ||
48 | </>) | 46 | </>) |
49 | : | 47 | : |
50 | (<> | 48 | (<> | ... | ... |
1 | import React, { useState } from 'react'; | 1 | import React, { useState } from 'react'; |
2 | +import cookie from 'react-cookies' | ||
2 | import { Button, Form, FormGroup, Label, Input} from 'reactstrap'; | 3 | import { Button, Form, FormGroup, Label, Input} from 'reactstrap'; |
3 | import { FacebookLoginButton } from 'react-social-login-buttons'; | 4 | import { FacebookLoginButton } from 'react-social-login-buttons'; |
4 | 5 | ||
... | @@ -30,6 +31,11 @@ const SigninPage = (props) => { | ... | @@ -30,6 +31,11 @@ const SigninPage = (props) => { |
30 | 31 | ||
31 | if (response.message === "Token issue") { | 32 | if (response.message === "Token issue") { |
32 | localStorage.setItem("user", JSON.stringify(response.token)); | 33 | localStorage.setItem("user", JSON.stringify(response.token)); |
34 | + const expires = new Date() | ||
35 | + expires.setDate(expires.getDate() + 60) | ||
36 | + cookie.save('username', response.username, { | ||
37 | + expires | ||
38 | + }) | ||
33 | alert('Login success'); | 39 | alert('Login success'); |
34 | props.history.push('/mypick'); | 40 | props.history.push('/mypick'); |
35 | } else if(response.message === "user does not exist"){ | 41 | } else if(response.message === "user does not exist"){ | ... | ... |
... | @@ -98,12 +98,16 @@ app.post("/api/signin", (req, res) => { | ... | @@ -98,12 +98,16 @@ app.post("/api/signin", (req, res) => { |
98 | } | 98 | } |
99 | ); | 99 | ); |
100 | 100 | ||
101 | + | ||
101 | return res.json({ | 102 | return res.json({ |
102 | code: 200, | 103 | code: 200, |
103 | message: 'Token issue', | 104 | message: 'Token issue', |
104 | token, | 105 | token, |
106 | + username : name | ||
105 | }); | 107 | }); |
106 | 108 | ||
109 | + | ||
110 | + | ||
107 | } catch (error) { | 111 | } catch (error) { |
108 | console.error(error); | 112 | console.error(error); |
109 | return res.status(500).json({ | 113 | return res.status(500).json({ | ... | ... |
-
Please register or login to post a comment