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