diff options
Diffstat (limited to 'frontend/src/components/login.js')
| -rw-r--r-- | frontend/src/components/login.js | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/frontend/src/components/login.js b/frontend/src/components/login.js deleted file mode 100644 index f86ad44..0000000 --- a/frontend/src/components/login.js +++ /dev/null | |||
| @@ -1,61 +0,0 @@ | |||
| 1 | import React from 'react'; | ||
| 2 | import { Link } from "react-router-dom"; | ||
| 3 | |||
| 4 | import "./login.css"; | ||
| 5 | import img1 from "../imgs/login.png" | ||
| 6 | import img2 from "../imgs/10.png" | ||
| 7 | import img3 from "../imgs/11.png" | ||
| 8 | |||
| 9 | |||
| 10 | export default function Login(prop) { | ||
| 11 | const {setToken,profile,setProfile} = prop | ||
| 12 | function login() { | ||
| 13 | window.location.href="https://lp.ardapektezol.com/api/v1/login" | ||
| 14 | } | ||
| 15 | function logout() { | ||
| 16 | setIsLoggedIn(false) | ||
| 17 | setProfile(null) | ||
| 18 | setToken(null) | ||
| 19 | fetch(`https://lp.ardapektezol.com/api/v1/token`,{'method':'DELETE'}) | ||
| 20 | .then(r=>window.location.href="/") | ||
| 21 | } | ||
| 22 | const [isLoggedIn, setIsLoggedIn] = React.useState(false); | ||
| 23 | React.useEffect(() => { | ||
| 24 | fetch(`https://lp.ardapektezol.com/api/v1/token`) | ||
| 25 | .then(r => r.json()) | ||
| 26 | .then(d => { | ||
| 27 | if (d.data != null) { | ||
| 28 | setToken(d.data.token) | ||
| 29 | } | ||
| 30 | }) | ||
| 31 | }, []); | ||
| 32 | |||
| 33 | |||
| 34 | React.useEffect(() => { | ||
| 35 | if(profile!==null){setIsLoggedIn(true)} | ||
| 36 | }, [profile]); | ||
| 37 | |||
| 38 | return ( | ||
| 39 | <> | ||
| 40 | {isLoggedIn ? ( | ||
| 41 | <Link to="/profile" tabIndex={-1} className='login'> | ||
| 42 | <button className='sidebar-button'> | ||
| 43 | <img src={profile.avatar_link} alt="" /> | ||
| 44 | <span>{profile.user_name}</span> | ||
| 45 | </button> | ||
| 46 | <button className='sidebar-button' onClick={logout}><img src={img3} alt="" /><span></span></button> | ||
| 47 | </Link> | ||
| 48 | ) : ( | ||
| 49 | <Link tabIndex={-1} className='login' > | ||
| 50 | <button className='sidebar-button' onClick={login}> | ||
| 51 | <img src={img2} alt="" /> | ||
| 52 | <span><img src={img1} alt="Sign in through Steam" /></span> | ||
| 53 | </button> | ||
| 54 | <button className='sidebar-button' disabled><span></span></button> | ||
| 55 | </Link> | ||
| 56 | )} | ||
| 57 | </> | ||
| 58 | ) | ||
| 59 | } | ||
| 60 | |||
| 61 | |||