aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/login.js
blob: 8dea3834c16bb1f638f1be4d7e759dbaebd59220 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
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() {

function login() {
    window.location.href="https://lp.ardapektezol.com/api/v1/login"
}
function logout() {
    Cookies.remove('token')
    setToken(null)
    window.location.href="/"
}
const [token, setToken] = React.useState(null);
const isLoggedIn = token !== null;
React.useEffect(() => {
    fetch(`/api/v1/token`)
    .then(r => r.json())
    .then(d => {
      setToken(d.data.token);
      console.log(d);
    })
    }, []);

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


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 className='login'>
        <button onClick={login}>
            <img src={img2} alt="" />
            <span><img src={img1} alt="Sign in through Steam" /></span>
        </button>
        <button disabled><span></span></button>
    </Link>
    )}
     </>   
        )
}