diff options
Diffstat (limited to 'frontend/src/components')
| -rw-r--r-- | frontend/src/components/login.js | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/frontend/src/components/login.js b/frontend/src/components/login.js index 8dea383..fc63760 100644 --- a/frontend/src/components/login.js +++ b/frontend/src/components/login.js | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | import React from 'react'; | 1 | import React from 'react'; |
| 2 | import { Link } from "react-router-dom"; | 2 | import { Link } from "react-router-dom"; |
| 3 | import Cookies from 'js-cookie'; | ||
| 4 | 3 | ||
| 5 | import "./login.css"; | 4 | import "./login.css"; |
| 6 | import img1 from "../imgs/login.png" | 5 | import img1 from "../imgs/login.png" |
| @@ -14,8 +13,8 @@ function login() { | |||
| 14 | window.location.href="https://lp.ardapektezol.com/api/v1/login" | 13 | window.location.href="https://lp.ardapektezol.com/api/v1/login" |
| 15 | } | 14 | } |
| 16 | function logout() { | 15 | function logout() { |
| 17 | Cookies.remove('token') | ||
| 18 | setToken(null) | 16 | setToken(null) |
| 17 | fetch(`/api/v1/token`,{'method':'DELETE'}) | ||
| 19 | window.location.href="/" | 18 | window.location.href="/" |
| 20 | } | 19 | } |
| 21 | const [token, setToken] = React.useState(null); | 20 | const [token, setToken] = React.useState(null); |
| @@ -25,7 +24,6 @@ React.useEffect(() => { | |||
| 25 | .then(r => r.json()) | 24 | .then(r => r.json()) |
| 26 | .then(d => { | 25 | .then(d => { |
| 27 | setToken(d.data.token); | 26 | setToken(d.data.token); |
| 28 | console.log(d); | ||
| 29 | }) | 27 | }) |
| 30 | }, []); | 28 | }, []); |
| 31 | 29 | ||
| @@ -37,7 +35,7 @@ React.useEffect(() => { | |||
| 37 | Authorization: token | 35 | Authorization: token |
| 38 | }}) | 36 | }}) |
| 39 | .then(r => r.json()) | 37 | .then(r => r.json()) |
| 40 | .then(d => {setProfile(d);console.log(d)}) | 38 | .then(d => setProfile(d.data)) |
| 41 | }, [token]); | 39 | }, [token]); |
| 42 | 40 | ||
| 43 | 41 | ||
| @@ -46,13 +44,13 @@ return ( | |||
| 46 | {isLoggedIn ? ( | 44 | {isLoggedIn ? ( |
| 47 | <Link to="/profile" tabIndex={-1} className='login'> | 45 | <Link to="/profile" tabIndex={-1} className='login'> |
| 48 | <button> | 46 | <button> |
| 49 | <img src={img2} alt="" /> | 47 | <img src={profile.avatar_link} alt="" /> |
| 50 | <span>Username</span> | 48 | <span>{profile.user_name}</span> |
| 51 | </button> | 49 | </button> |
| 52 | <button onClick={logout}><img src={img3} alt="" /><span></span></button> | 50 | <button onClick={logout}><img src={img3} alt="" /><span></span></button> |
| 53 | </Link> | 51 | </Link> |
| 54 | ) : ( | 52 | ) : ( |
| 55 | <Link className='login'> | 53 | <Link tabIndex={-1} className='login'> |
| 56 | <button onClick={login}> | 54 | <button onClick={login}> |
| 57 | <img src={img2} alt="" /> | 55 | <img src={img2} alt="" /> |
| 58 | <span><img src={img1} alt="Sign in through Steam" /></span> | 56 | <span><img src={img1} alt="Sign in through Steam" /></span> |