diff options
| author | Nidboj132 <lol2s@vp.plm> | 2023-05-06 17:16:43 +0200 |
|---|---|---|
| committer | Nidboj132 <lol2s@vp.plm> | 2023-05-06 17:16:43 +0200 |
| commit | 51a553ad7912525a286bf9d18ceb028c266c5561 (patch) | |
| tree | 73f07f62cbdcba59faf981e6b1c49634642de697 /frontend/src/components | |
| parent | Merge pull request #41 from Nidboj132/main (diff) | |
| download | lphub-51a553ad7912525a286bf9d18ceb028c266c5561.tar.gz lphub-51a553ad7912525a286bf9d18ceb028c266c5561.tar.bz2 lphub-51a553ad7912525a286bf9d18ceb028c266c5561.zip | |
login test
Diffstat (limited to 'frontend/src/components')
| -rw-r--r-- | frontend/src/components/login.js | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/frontend/src/components/login.js b/frontend/src/components/login.js index 4ef1e2a..258e9c7 100644 --- a/frontend/src/components/login.js +++ b/frontend/src/components/login.js | |||
| @@ -1,6 +1,5 @@ | |||
| 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"; | ||
| 4 | 3 | ||
| 5 | import "./login.css"; | 4 | import "./login.css"; |
| 6 | import img1 from "../imgs/login.png" | 5 | import img1 from "../imgs/login.png" |
| @@ -10,22 +9,31 @@ import img3 from "../imgs/11.png" | |||
| 10 | 9 | ||
| 11 | export default function Login() { | 10 | export default function Login() { |
| 12 | 11 | ||
| 13 | const isLoggedIn = Cookies.get('token') !== undefined; | 12 | function login() { |
| 14 | 13 | window.location.href="https://lp.ardapektezol.com/api/v1/login" | |
| 14 | } | ||
| 15 | function logout() { | 15 | function logout() { |
| 16 | Cookies.remove('token') | 16 | setToken(null) |
| 17 | window.location.href="/" | 17 | window.location.href="/" |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | const [data, setData] = React.useState(); | 20 | const [token, setToken] = React.useState(null); |
| 21 | const isLoggedIn = token !== null; | ||
| 22 | React.useEffect(() => { | ||
| 23 | fetch(`/api/v1/token`) | ||
| 24 | .then(r => {console.log(r)}) | ||
| 25 | .then(d => {setToken(d.data.token);console.log(d)}) | ||
| 26 | }, []); | ||
| 27 | |||
| 28 | const [[profile], setProfile] = React.useState(); | ||
| 21 | React.useEffect(() => { | 29 | React.useEffect(() => { |
| 22 | fetch(`/api/v1/profile`,{ | 30 | fetch(`/api/v1/profile`,{ |
| 23 | headers: { | 31 | headers: { |
| 24 | 'Content-Type': 'application/json', | 32 | 'Content-Type': 'application/json', |
| 25 | Authorization: Cookies.get('token') | 33 | Authorization: token |
| 26 | }}) | 34 | }}) |
| 27 | .then(r => {console.log(r)}) | 35 | .then(r => {console.log(r)}) |
| 28 | .then(d => {setData(d);console.log(d)}) | 36 | .then(d => {setProfile(d);console.log(d)}) |
| 29 | }, []); | 37 | }, []); |
| 30 | 38 | ||
| 31 | return ( | 39 | return ( |
| @@ -39,8 +47,8 @@ return ( | |||
| 39 | <button onClick={logout}><img src={img3} alt="" /><span></span></button> | 47 | <button onClick={logout}><img src={img3} alt="" /><span></span></button> |
| 40 | </Link> | 48 | </Link> |
| 41 | ) : ( | 49 | ) : ( |
| 42 | <Link to="/api/v1/login" className='login'> | 50 | <Link className='login'> |
| 43 | <button> | 51 | <button onClick={login}> |
| 44 | <img src={img2} alt="" /> | 52 | <img src={img2} alt="" /> |
| 45 | <span><img src={img1} alt="Sign in through Steam" /></span> | 53 | <span><img src={img1} alt="Sign in through Steam" /></span> |
| 46 | </button> | 54 | </button> |