diff options
| author | Nidboj132 <lol2s@vp.plm> | 2023-05-06 19:58:27 +0200 |
|---|---|---|
| committer | Nidboj132 <lol2s@vp.plm> | 2023-05-06 19:58:27 +0200 |
| commit | 4451ed109b05679118b5410fba111b370d8956ed (patch) | |
| tree | 3dbddf944802cb6149adc2c747112b3986ec6701 /frontend/src/components | |
| parent | login (diff) | |
| download | lphub-4451ed109b05679118b5410fba111b370d8956ed.tar.gz lphub-4451ed109b05679118b5410fba111b370d8956ed.tar.bz2 lphub-4451ed109b05679118b5410fba111b370d8956ed.zip | |
login
Diffstat (limited to 'frontend/src/components')
| -rw-r--r-- | frontend/src/components/login.js | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/frontend/src/components/login.js b/frontend/src/components/login.js index 7ddb706..6cb196b 100644 --- a/frontend/src/components/login.js +++ b/frontend/src/components/login.js | |||
| @@ -14,6 +14,7 @@ function login() { | |||
| 14 | } | 14 | } |
| 15 | function logout() { | 15 | function logout() { |
| 16 | fetch(`/api/v1/token`,{'method':'DELETE'}) | 16 | fetch(`/api/v1/token`,{'method':'DELETE'}) |
| 17 | setToken(null) | ||
| 17 | setIsLoggedIn(false) | 18 | setIsLoggedIn(false) |
| 18 | window.location.href="/" | 19 | window.location.href="/" |
| 19 | } | 20 | } |
| @@ -22,10 +23,7 @@ const [isLoggedIn, setIsLoggedIn] = React.useState(false); | |||
| 22 | React.useEffect(() => { | 23 | React.useEffect(() => { |
| 23 | fetch(`/api/v1/token`) | 24 | fetch(`/api/v1/token`) |
| 24 | .then(r => r.json()) | 25 | .then(r => r.json()) |
| 25 | .then(d => { | 26 | .then(d => setToken(d.data.token)) |
| 26 | setToken(d.data.token); | ||
| 27 | setIsLoggedIn(true) | ||
| 28 | }) | ||
| 29 | }, []); | 27 | }, []); |
| 30 | 28 | ||
| 31 | const [profile, setProfile] = React.useState(undefined); | 29 | const [profile, setProfile] = React.useState(undefined); |
| @@ -36,7 +34,11 @@ React.useEffect(() => { | |||
| 36 | Authorization: token | 34 | Authorization: token |
| 37 | }}) | 35 | }}) |
| 38 | .then(r => r.json()) | 36 | .then(r => r.json()) |
| 39 | .then(d => {setProfile(d.data);console.log(d,profile)}) | 37 | .then(d => { |
| 38 | setProfile(d.data); | ||
| 39 | setIsLoggedIn(true) | ||
| 40 | console.log(d,profile) | ||
| 41 | }) | ||
| 40 | }, [token]); | 42 | }, [token]); |
| 41 | 43 | ||
| 42 | 44 | ||
| @@ -45,10 +47,10 @@ return ( | |||
| 45 | {isLoggedIn ? ( | 47 | {isLoggedIn ? ( |
| 46 | <Link to="/profile" tabIndex={-1} className='login'> | 48 | <Link to="/profile" tabIndex={-1} className='login'> |
| 47 | <button> | 49 | <button> |
| 48 | {/* <img src={profile.avatar_link} alt="" /> */} | 50 | <img src={profile.avatar_link} alt="" /> |
| 49 | <img src={img2} alt="" /> | 51 | {/* <img src={img2} alt="" /> */} |
| 50 | {/* <span>{profile.user_name}</span> */} | 52 | <span>{profile.user_name}</span> |
| 51 | <span>Username</span> | 53 | {/* <span>Username</span> */} |
| 52 | </button> | 54 | </button> |
| 53 | <button onClick={logout}><img src={img3} alt="" /><span></span></button> | 55 | <button onClick={logout}><img src={img3} alt="" /><span></span></button> |
| 54 | </Link> | 56 | </Link> |