diff options
Diffstat (limited to 'frontend/src/components/login.js')
| -rw-r--r-- | frontend/src/components/login.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/frontend/src/components/login.js b/frontend/src/components/login.js new file mode 100644 index 0000000..4ef1e2a --- /dev/null +++ b/frontend/src/components/login.js | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | import React from 'react'; | ||
| 2 | import { Link } from "react-router-dom"; | ||
| 3 | import Cookies from "js-cookie"; | ||
| 4 | |||
| 5 | import "./login.css"; | ||
| 6 | import img1 from "../imgs/login.png" | ||
| 7 | import img2 from "../imgs/10.png" | ||
| 8 | import img3 from "../imgs/11.png" | ||
| 9 | |||
| 10 | |||
| 11 | export default function Login() { | ||
| 12 | |||
| 13 | const isLoggedIn = Cookies.get('token') !== undefined; | ||
| 14 | |||
| 15 | function logout() { | ||
| 16 | Cookies.remove('token') | ||
| 17 | window.location.href="/" | ||
| 18 | } | ||
| 19 | |||
| 20 | const [data, setData] = React.useState(); | ||
| 21 | React.useEffect(() => { | ||
| 22 | fetch(`/api/v1/profile`,{ | ||
| 23 | headers: { | ||
| 24 | 'Content-Type': 'application/json', | ||
| 25 | Authorization: Cookies.get('token') | ||
| 26 | }}) | ||
| 27 | .then(r => {console.log(r)}) | ||
| 28 | .then(d => {setData(d);console.log(d)}) | ||
| 29 | }, []); | ||
| 30 | |||
| 31 | return ( | ||
| 32 | <> | ||
| 33 | {isLoggedIn ? ( | ||
| 34 | <Link to="/profile" tabIndex={-1} className='login'> | ||
| 35 | <button> | ||
| 36 | <img src={img2} alt="" /> | ||
| 37 | <span>Username</span> | ||
| 38 | </button> | ||
| 39 | <button onClick={logout}><img src={img3} alt="" /><span></span></button> | ||
| 40 | </Link> | ||
| 41 | ) : ( | ||
| 42 | <Link to="/api/v1/login" className='login'> | ||
| 43 | <button> | ||
| 44 | <img src={img2} alt="" /> | ||
| 45 | <span><img src={img1} alt="Sign in through Steam" /></span> | ||
| 46 | </button> | ||
| 47 | <button disabled><span></span></button> | ||
| 48 | </Link> | ||
| 49 | )} | ||
| 50 | </> | ||
| 51 | ) | ||
| 52 | } | ||
| 53 | |||
| 54 | |||