I have implemented firebase authentication to my node js app. The app requires an authorization token to send back page content, ignore otherwise. I can set window.location to apps profile page and render the page fine. But to add authorization header I can not load the page as main page rendered in the browser and I do not like the replace method of document inner html/similar because it feels cheap, and I want to replace the page or send user to the other page.
To add auth header I use xmlHttpRequest from JS. Everything is working. Now I need to render this page on browser. How can I do that?
code that retrieves the test profile page:
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Typical action to be performed when the document is ready:
console.log(xhttp.responseText);
//window.location = xhttp.responseText; //*** I get the output but How to show page?
}
};
xhttp.open("GET", "http://localhost:5000/profile/", true);
xhttp.setRequestHeader("Authorization", "Bearer "+tokens);
xhttp.send();
Am I doing it in the correct way? I did not find a better way to add auth header to requests. And if it is all right then how can I show the page on browser easily?