My application uses token-based authentication. On the login page, I send the user's data and password. I must receive a token to set it to localStorage . once it is received and established. render the welcome page.
This is my Front end code
const formDataSignin = new FormData(formSignin);
event.preventDefault();
const header =
{
method: 'post',
body: formDataSignin
}
fetch('/signin', header)
.then(res => res.json())
.then(res =>
{
localStorage.setItem('token', res.token);
});
My back End code
const newToken = token.createToken(answer);
res.render(user, {token, newToken})
return;