0
I’m frontending a login system and I’m using pure javascript for it. I can already log into the browser API and console to receive the data from the user who is logging in. This is my AJAX:
function loga() {
console.log("Enviando post");
let usuario = {
email: document.querySelector("#email").value,
senha: document.querySelector("#senha").value
};
let xhr = new XMLHttpRequest();
xhr.open("POST", "http:web/rest/logins", true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.addEventListener("load", function() {
console.log(xhr.responseText);
if( xhr.status == 200) {
window.location="interno/index.php";
}
if(xhr.status == 500) {
var dadosInvalidos = document.querySelector('#dados-invalidos');
dadosInvalidos.classList.remove('invisivel');
}
});
xhr.send(JSON.stringify(usuario));
}
The ones that appear to me on the console are the id and the rest of the user data. What I need to know now is how do I carry the user id to the homepage, that is, the page that comes after the user logs in, and thus get the user profile mounted on it. How can I do that? Can anyone help me? Thanks in advance.
Take a look at
sessionStorage
: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage– Max Rogério
So @Maxrogério I’m half layman and still can’t read documentations, so I’m using the Forum. You know how to do this?
– Francis Vagner da Luz
It has nothing to do with your doubt but, if you allow me an opinion: Pass user and password via http is not a good idea! Ever thought about encrypting using a public key and decrypting on the server? I usually do this using jsencrypt.
– PerryWerneck
So... I just develop forntend, I develop for a JAVA API created by my nephew, and I haven’t been a frontend developer for a long time, I don’t really know what jsencrypt is, but thanks for the tip, I’ll look into what it is
– Francis Vagner da Luz