aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/login.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/components/login.js')
-rw-r--r--frontend/src/components/login.js54
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 @@
1import React from 'react';
2import { Link } from "react-router-dom";
3import Cookies from "js-cookie";
4
5import "./login.css";
6import img1 from "../imgs/login.png"
7import img2 from "../imgs/10.png"
8import img3 from "../imgs/11.png"
9
10
11export default function Login() {
12
13const isLoggedIn = Cookies.get('token') !== undefined;
14
15function logout() {
16 Cookies.remove('token')
17 window.location.href="/"
18}
19
20const [data, setData] = React.useState();
21React.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
31return (
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