Skip to content

Instantly share code, notes, and snippets.

@souravs17031999
Created August 19, 2021 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save souravs17031999/127641dd2f238c5f0284c2526baf51eb to your computer and use it in GitHub Desktop.
Save souravs17031999/127641dd2f238c5f0284c2526baf51eb to your computer and use it in GitHub Desktop.
// 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