aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--frontend/package-lock.json14
-rw-r--r--frontend/package.json1
-rw-r--r--frontend/src/components/login.js27
3 files changed, 14 insertions, 28 deletions
diff --git a/frontend/package-lock.json b/frontend/package-lock.json
index 9bfe340..0c4569a 100644
--- a/frontend/package-lock.json
+++ b/frontend/package-lock.json
@@ -11,7 +11,6 @@
11 "@testing-library/jest-dom": "^5.16.5", 11 "@testing-library/jest-dom": "^5.16.5",
12 "@testing-library/react": "^13.4.0", 12 "@testing-library/react": "^13.4.0",
13 "@testing-library/user-event": "^13.5.0", 13 "@testing-library/user-event": "^13.5.0",
14 "js-cookie": "^3.0.5",
15 "react": "^18.2.0", 14 "react": "^18.2.0",
16 "react-dom": "^18.2.0", 15 "react-dom": "^18.2.0",
17 "react-scripts": "5.0.1", 16 "react-scripts": "5.0.1",
@@ -11531,14 +11530,6 @@
11531 "url": "https://github.com/chalk/supports-color?sponsor=1" 11530 "url": "https://github.com/chalk/supports-color?sponsor=1"
11532 } 11531 }
11533 }, 11532 },
11534 "node_modules/js-cookie": {
11535 "version": "3.0.5",
11536 "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz",
11537 "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==",
11538 "engines": {
11539 "node": ">=14"
11540 }
11541 },
11542 "node_modules/js-sdsl": { 11533 "node_modules/js-sdsl": {
11543 "version": "4.3.0", 11534 "version": "4.3.0",
11544 "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz", 11535 "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz",
@@ -25466,11 +25457,6 @@
25466 } 25457 }
25467 } 25458 }
25468 }, 25459 },
25469 "js-cookie": {
25470 "version": "3.0.5",
25471 "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz",
25472 "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw=="
25473 },
25474 "js-sdsl": { 25460 "js-sdsl": {
25475 "version": "4.3.0", 25461 "version": "4.3.0",
25476 "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz", 25462 "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz",
diff --git a/frontend/package.json b/frontend/package.json
index 72e2117..123a434 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -6,7 +6,6 @@
6 "@testing-library/jest-dom": "^5.16.5", 6 "@testing-library/jest-dom": "^5.16.5",
7 "@testing-library/react": "^13.4.0", 7 "@testing-library/react": "^13.4.0",
8 "@testing-library/user-event": "^13.5.0", 8 "@testing-library/user-event": "^13.5.0",
9 "js-cookie": "^3.0.5",
10 "react": "^18.2.0", 9 "react": "^18.2.0",
11 "react-dom": "^18.2.0", 10 "react-dom": "^18.2.0",
12 "react-scripts": "5.0.1", 11 "react-scripts": "5.0.1",
diff --git a/frontend/src/components/login.js b/frontend/src/components/login.js
index 8dea383..7bff5f0 100644
--- a/frontend/src/components/login.js
+++ b/frontend/src/components/login.js
@@ -1,6 +1,5 @@
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';
4 3
5import "./login.css"; 4import "./login.css";
6import img1 from "../imgs/login.png" 5import img1 from "../imgs/login.png"
@@ -14,22 +13,21 @@ function login() {
14 window.location.href="https://lp.ardapektezol.com/api/v1/login" 13 window.location.href="https://lp.ardapektezol.com/api/v1/login"
15} 14}
16function logout() { 15function logout() {
17 Cookies.remove('token') 16 setIsLoggedIn(false)
17 setProfile(null)
18 setToken(null) 18 setToken(null)
19 window.location.href="/" 19 fetch(`/api/v1/token`,{'method':'DELETE'})
20 .then(r=>window.location.href="/")
20} 21}
21const [token, setToken] = React.useState(null); 22const [token, setToken] = React.useState(null);
22const isLoggedIn = token !== null; 23const [isLoggedIn, setIsLoggedIn] = React.useState(false);
23React.useEffect(() => { 24React.useEffect(() => {
24 fetch(`/api/v1/token`) 25 fetch(`/api/v1/token`)
25 .then(r => r.json()) 26 .then(r => r.json())
26 .then(d => { 27 .then(d => setToken(d.data.token))
27 setToken(d.data.token);
28 console.log(d);
29 })
30 }, []); 28 }, []);
31 29
32const [profile, setProfile] = React.useState(); 30const [profile, setProfile] = React.useState(null);
33React.useEffect(() => { 31React.useEffect(() => {
34 fetch(`/api/v1/profile`,{ 32 fetch(`/api/v1/profile`,{
35 headers: { 33 headers: {
@@ -37,22 +35,25 @@ React.useEffect(() => {
37 Authorization: token 35 Authorization: token
38 }}) 36 }})
39 .then(r => r.json()) 37 .then(r => r.json())
40 .then(d => {setProfile(d);console.log(d)}) 38 .then(d => setProfile(d.data))
41 }, [token]); 39 }, [token]);
42 40
41React.useEffect(() => {
42 if(profile!==null){setIsLoggedIn(true)}
43 }, [profile]);
43 44
44return ( 45return (
45 <> 46 <>
46 {isLoggedIn ? ( 47 {isLoggedIn ? (
47 <Link to="/profile" tabIndex={-1} className='login'> 48 <Link to="/profile" tabIndex={-1} className='login'>
48 <button> 49 <button>
49 <img src={img2} alt="" /> 50 <img src={profile.avatar_link} alt="" />
50 <span>Username</span> 51 <span>{profile.user_name}</span>
51 </button> 52 </button>
52 <button onClick={logout}><img src={img3} alt="" /><span></span></button> 53 <button onClick={logout}><img src={img3} alt="" /><span></span></button>
53 </Link> 54 </Link>
54 ) : ( 55 ) : (
55 <Link className='login'> 56 <Link tabIndex={-1} className='login'>
56 <button onClick={login}> 57 <button onClick={login}>
57 <img src={img2} alt="" /> 58 <img src={img2} alt="" />
58 <span><img src={img1} alt="Sign in through Steam" /></span> 59 <span><img src={img1} alt="Sign in through Steam" /></span>