diff options
Diffstat (limited to 'frontend/src/components/login.js')
| -rw-r--r-- | frontend/src/components/login.js | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/frontend/src/components/login.js b/frontend/src/components/login.js index 204007f..2b735cb 100644 --- a/frontend/src/components/login.js +++ b/frontend/src/components/login.js | |||
| @@ -8,7 +8,7 @@ import img3 from "../imgs/11.png" | |||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | export default function Login(prop) { | 10 | export default function Login(prop) { |
| 11 | const {token,setToken} = prop | 11 | const {setToken,profile,setProfile} = prop |
| 12 | function login() { | 12 | function login() { |
| 13 | window.location.href="https://lp.ardapektezol.com/api/v1/login" | 13 | window.location.href="https://lp.ardapektezol.com/api/v1/login" |
| 14 | } | 14 | } |
| @@ -16,26 +16,16 @@ function logout() { | |||
| 16 | setIsLoggedIn(false) | 16 | setIsLoggedIn(false) |
| 17 | setProfile(null) | 17 | setProfile(null) |
| 18 | setToken(null) | 18 | setToken(null) |
| 19 | fetch(`/api/v1/token`,{'method':'DELETE'}) | 19 | fetch(`https://lp.ardapektezol.com/api/v1/token`,{'method':'DELETE'}) |
| 20 | .then(r=>window.location.href="/") | 20 | .then(r=>window.location.href="/") |
| 21 | } | 21 | } |
| 22 | const [isLoggedIn, setIsLoggedIn] = React.useState(false); | 22 | const [isLoggedIn, setIsLoggedIn] = React.useState(false); |
| 23 | React.useEffect(() => { | 23 | React.useEffect(() => { |
| 24 | fetch(`/api/v1/token`) | 24 | fetch(`https://lp.ardapektezol.com/api/v1/token`) |
| 25 | .then(r => r.json()) | 25 | .then(r => r.json()) |
| 26 | .then(d => setToken(d.data.token)) | 26 | .then(d => setToken(d.data.token)) |
| 27 | }, []); | 27 | }, []); |
| 28 | 28 | ||
| 29 | const [profile, setProfile] = React.useState(null); | ||
| 30 | React.useEffect(() => { | ||
| 31 | fetch(`/api/v1/profile`,{ | ||
| 32 | headers: { | ||
| 33 | 'Content-Type': 'application/json', | ||
| 34 | Authorization: token | ||
| 35 | }}) | ||
| 36 | .then(r => r.json()) | ||
| 37 | .then(d => setProfile(d.data)) | ||
| 38 | }, [token]); | ||
| 39 | 29 | ||
| 40 | React.useEffect(() => { | 30 | React.useEffect(() => { |
| 41 | if(profile!==null){setIsLoggedIn(true)} | 31 | if(profile!==null){setIsLoggedIn(true)} |