const [data, setData] = useState({errorMessage: "", isLoading: false}); const auth = useSelector((state) => state.auth); console.log("auth state == ", auth); const dispatch = useDispatch(); useEffect(() => { console.log("Data ", data); console.log("auth ", auth); const url = window.location.href; const hasCode = url.includes("?code="); console.log("url = ", url); console.log(" hascode ", hasCode) if (hasCode) { const newUrl = url.split("?code="); window.history.pushState({}, null, newUrl[0]); setData({...data, isLoading:true}) const requestData = { code: newUrl[1] }; // dispatch(setAuthCode(newUrl[0])) const serverURL = `http://localhost:8080/authcode?code=${requestData.code}`; console.log("server url ", serverURL) // Use code parameter and other parameters to make POST request to proxy_server fetch(serverURL, { method: "POST", body: JSON.stringify(requestData) }) .then(response =>{ return response.headers.get('Authorization');}) .then(data => { console.log("Data after post response ", data) dispatch(signIn()) }) .catch(error => { setData({ isLoading: false, errorMessage: "Sorry! Login failed" }); }); } // props.signIn(); },[data, auth, dispatch]); if (auth.isSignedIn) { console.log("Redirecting now ", auth.isSignedIn) return ; }