diff options
| author | Nidboj132 <lol2s@vp.plm> | 2023-05-06 17:51:01 +0200 |
|---|---|---|
| committer | Nidboj132 <lol2s@vp.plm> | 2023-05-06 17:51:01 +0200 |
| commit | 9d532e86571453c5db59979416fc0428f2e80a22 (patch) | |
| tree | f3f995596c743742211731d1dedef64f45029de7 /frontend | |
| parent | login test (diff) | |
| download | lphub-9d532e86571453c5db59979416fc0428f2e80a22.tar.gz lphub-9d532e86571453c5db59979416fc0428f2e80a22.tar.bz2 lphub-9d532e86571453c5db59979416fc0428f2e80a22.zip | |
login test
Diffstat (limited to 'frontend')
| -rw-r--r-- | frontend/src/components/login.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/frontend/src/components/login.js b/frontend/src/components/login.js index 507cf5b..558bc8f 100644 --- a/frontend/src/components/login.js +++ b/frontend/src/components/login.js | |||
| @@ -16,13 +16,15 @@ function logout() { | |||
| 16 | setToken(null) | 16 | setToken(null) |
| 17 | window.location.href="/" | 17 | window.location.href="/" |
| 18 | } | 18 | } |
| 19 | |||
| 20 | const [token, setToken] = React.useState(null); | 19 | const [token, setToken] = React.useState(null); |
| 21 | const isLoggedIn = token !== null; | 20 | const isLoggedIn = token !== null; |
| 22 | React.useEffect(() => { | 21 | React.useEffect(() => { |
| 23 | fetch(`/api/v1/token`) | 22 | fetch(`/api/v1/token`) |
| 24 | .then(r => {console.log(r)}) | 23 | .then(r => r.json()) |
| 25 | .then(d => {setToken(d.data.token);console.log(d)}) | 24 | .then(d => { |
| 25 | setToken(d.data.token); | ||
| 26 | console.log(d); | ||
| 27 | }) | ||
| 26 | }, []); | 28 | }, []); |
| 27 | 29 | ||
| 28 | const [profile, setProfile] = React.useState(); | 30 | const [profile, setProfile] = React.useState(); |
| @@ -32,10 +34,11 @@ React.useEffect(() => { | |||
| 32 | 'Content-Type': 'application/json', | 34 | 'Content-Type': 'application/json', |
| 33 | Authorization: token | 35 | Authorization: token |
| 34 | }}) | 36 | }}) |
| 35 | .then(r => {console.log(r)}) | 37 | .then(r => r.json()) |
| 36 | .then(d => {setProfile(d);console.log(d)}) | 38 | .then(d => {setProfile(d);console.log(d)}) |
| 37 | }, []); | 39 | }, []); |
| 38 | 40 | ||
| 41 | |||
| 39 | return ( | 42 | return ( |
| 40 | <> | 43 | <> |
| 41 | {isLoggedIn ? ( | 44 | {isLoggedIn ? ( |