diff options
| -rw-r--r-- | frontend/src/components/login.js | 33 |
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 @@ | |||
| 1 | import React from 'react'; | 1 | import React from 'react'; |
| 2 | import { Link } from "react-router-dom"; | 2 | import { Link } from "react-router-dom"; |
| 3 | import Cookies from "js-cookie"; | 3 | import Cookies from 'js-cookie'; |
| 4 | 4 | ||
| 5 | import "./login.css"; | 5 | import "./login.css"; |
| 6 | import img1 from "../imgs/login.png" | 6 | import img1 from "../imgs/login.png" |
| @@ -10,23 +10,36 @@ import img3 from "../imgs/11.png" | |||
| 10 | 10 | ||
| 11 | export default function Login() { | 11 | export default function Login() { |
| 12 | 12 | ||
| 13 | const isLoggedIn = Cookies.get('token') !== undefined; | 13 | function login() { |
| 14 | 14 | window.location.href="https://lp.ardapektezol.com/api/v1/login" | |
| 15 | } | ||
| 15 | function logout() { | 16 | function logout() { |
| 16 | Cookies.remove('token') | 17 | Cookies.remove('token') |
| 18 | setToken(null) | ||
| 17 | window.location.href="/" | 19 | window.location.href="/" |
| 18 | } | 20 | } |
| 21 | const [token, setToken] = React.useState(null); | ||
| 22 | const isLoggedIn = token !== null; | ||
| 23 | React.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 | ||
| 20 | const [data, setData] = React.useState(); | 32 | const [profile, setProfile] = React.useState(); |
| 21 | React.useEffect(() => { | 33 | React.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 | ||
| 31 | return ( | 44 | return ( |
| 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> |