Created
August 19, 2021 18:29
-
-
Save souravs17031999/127641dd2f238c5f0284c2526baf51eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// user should be authenticated on initial loading of page and then set user data in context on the page | |
window.onload = initialPageLoad | |
function initialPageLoad() { | |
fetchUserData(user_id); | |
} | |
function fetchUserData(user_id) { | |
url = configTestEnv["userServiceHost"] + "/user/fetch-user-data?" | |
url += `user_id=${user_id}` | |
fetch(url, { | |
method: 'GET', | |
}) | |
.then(response => { | |
if(response.status === 401) { | |
window.location.href = "/app/login.html" | |
return; | |
} | |
return response.json()}) | |
.then(data => { | |
if(data["status"] == "success") { | |
setUserDataInContext(data); | |
} else { | |
alert(`No data found, ERROR: ", ${data["message"]}`) | |
} | |
}) | |
.catch((error) => { | |
console.log(error) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment