From 8a3107ed9fabbcb17fbe02985140121010067f84 Mon Sep 17 00:00:00 2001 From: Nidboj132 Date: Sat, 6 May 2023 20:16:19 +0200 Subject: login --- frontend/src/components/login.js | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'frontend/src/components/login.js') diff --git a/frontend/src/components/login.js b/frontend/src/components/login.js index 08c8114..db8cc4c 100644 --- a/frontend/src/components/login.js +++ b/frontend/src/components/login.js @@ -15,6 +15,7 @@ function login() { function logout() { fetch(`/api/v1/token`,{'method':'DELETE'}) setToken(null) + setProfile(null) setIsLoggedIn(false) window.location.href="/" } @@ -26,7 +27,7 @@ React.useEffect(() => { .then(d => setToken(d.data.token)) }, []); -const [profile, setProfile] = React.useState(undefined); +const [profile, setProfile] = React.useState(null); React.useEffect(() => { fetch(`/api/v1/profile`,{ headers: { @@ -34,31 +35,20 @@ React.useEffect(() => { Authorization: token }}) .then(r => r.json()) - .then(d => { - - console.log("data:", d); - setProfile(d.data); - console.log("profile:", profile); - }) - .catch(error => { - console.log("error:", error); - }); + .then(d => setProfile(d.data)) }, [token]); React.useEffect(() => { - console.log("profile 2:", profile); - setIsLoggedIn(true) -}, [profile]); + if(profile!==null){setIsLoggedIn(true)} + }, [profile]); return ( <> {isLoggedIn ? ( -- cgit v1.2.3