aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/login.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/components/login.js')
-rw-r--r--frontend/src/components/login.js16
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
10export default function Login(prop) { 10export default function Login(prop) {
11const {token,setToken} = prop 11const {setToken,profile,setProfile} = prop
12function login() { 12function 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}
22const [isLoggedIn, setIsLoggedIn] = React.useState(false); 22const [isLoggedIn, setIsLoggedIn] = React.useState(false);
23React.useEffect(() => { 23React.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
29const [profile, setProfile] = React.useState(null);
30React.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
40React.useEffect(() => { 30React.useEffect(() => {
41 if(profile!==null){setIsLoggedIn(true)} 31 if(profile!==null){setIsLoggedIn(true)}