aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--frontend/src/components/login.js24
1 files changed, 7 insertions, 17 deletions
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() {
15function logout() { 15function logout() {
16 fetch(`/api/v1/token`,{'method':'DELETE'}) 16 fetch(`/api/v1/token`,{'method':'DELETE'})
17 setToken(null) 17 setToken(null)
18 setProfile(null)
18 setIsLoggedIn(false) 19 setIsLoggedIn(false)
19 window.location.href="/" 20 window.location.href="/"
20} 21}
@@ -26,7 +27,7 @@ React.useEffect(() => {
26 .then(d => setToken(d.data.token)) 27 .then(d => setToken(d.data.token))
27 }, []); 28 }, []);
28 29
29const [profile, setProfile] = React.useState(undefined); 30const [profile, setProfile] = React.useState(null);
30React.useEffect(() => { 31React.useEffect(() => {
31 fetch(`/api/v1/profile`,{ 32 fetch(`/api/v1/profile`,{
32 headers: { 33 headers: {
@@ -34,31 +35,20 @@ React.useEffect(() => {
34 Authorization: token 35 Authorization: token
35 }}) 36 }})
36 .then(r => r.json()) 37 .then(r => r.json())
37 .then(d => { 38 .then(d => setProfile(d.data))
38
39 console.log("data:", d);
40 setProfile(d.data);
41 console.log("profile:", profile);
42 })
43 .catch(error => {
44 console.log("error:", error);
45 });
46 }, [token]); 39 }, [token]);
47 40
48React.useEffect(() => { 41React.useEffect(() => {
49 console.log("profile 2:", profile); 42 if(profile!==null){setIsLoggedIn(true)}
50 setIsLoggedIn(true) 43 }, [profile]);
51}, [profile]);
52 44
53return ( 45return (
54 <> 46 <>
55 {isLoggedIn ? ( 47 {isLoggedIn ? (
56 <Link to="/profile" tabIndex={-1} className='login'> 48 <Link to="/profile" tabIndex={-1} className='login'>
57 <button> 49 <button>
58 {/* <img src={profile.avatar_link} alt="" /> */} 50 <img src={profile.avatar_link} alt="" />
59 <img src={img2} alt="" /> 51 <span>{profile.user_name}</span>
60 {/* <span>{profile.user_name}</span> */}
61 <span>Username</span>
62 </button> 52 </button>
63 <button onClick={logout}><img src={img3} alt="" /><span></span></button> 53 <button onClick={logout}><img src={img3} alt="" /><span></span></button>
64 </Link> 54 </Link>