0
I have a login application where the user type the username and password, then I make a POST request with ajax according to the code below:
<script >
$(document).on('click',".entrar",function(e){
e.preventDefault();
let name = document.getElementById('user').value;
let pass = document.getElementById('pass').value;
if(name.length && pass.length){
$.ajax({
url:"http://localhost:8081/auth/login",
method:"POST",
data:{
name:name,
pass:pass
},
async:true,
success:function(data){
if(/Senha|Usuário/i.test(data)){
document.getElementById("alerta").style.display = "block";
$("#erro").html(data);
}else{
}
},
});
}
});
</script>
The return of the ajax, in the function of Success, is a message informing if the user is incorrect or the password , that if one of the information is incorrect, if everything is ok, the return is an authorization token.
What I want to do, is if I am receiving the token ,I need to redirect to http://localhost:8081/Projects however, need to pass an authorization header for this link containing the token would be something like 'Authorization': 'Bearer ' + token;
How do I get the token ,redirect the page by passing this token in the header, the redirect part would be inside Else
Got it, thank you
– mecatrônica com reciclagem