aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/login.js
blob: 4ef1e2a26ec2cf91929a00d172615647b6092f46 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React from 'react';
import { Link } from "react-router-dom";
import Cookies from "js-cookie";

import "./login.css";
import img1 from "../imgs/login.png"
import img2 from "../imgs/10.png"
import img3 from "../imgs/11.png"


export default function Login() {

const isLoggedIn = Cookies.get('token') !== undefined;

function logout() {
    Cookies.remove('token')
    window.location.href="/"
}

const [data, setData] = React.useState();
React.useEffect(() => {
    fetch(`/api/v1/profile`,{
        headers: {
			'Content-Type': 'application/json',
            Authorization: Cookies.get('token')
        }})
    .then(r => {console.log(r)})
    .then(d => {setData(d);console.log(d)})
    }, []);

return (
    <>
    {isLoggedIn ? (
    <Link to="/profile" tabIndex={-1} className='login'>
        <button>
            <img src={img2} alt="" />
            <span>Username</span>
        </button>
        <button onClick={logout}><img src={img3} alt="" /><span></span></button>
    </Link>
    ) : (
    <Link to="/api/v1/login" className='login'>
        <button>
            <img src={img2} alt="" />
            <span><img src={img1} alt="Sign in through Steam" /></span>
        </button>
        <button disabled><span></span></button>
    </Link>
    )}
     </>   
        )
}