I have a basic node.js app serving a static index.html that contains a JS app. I have a login route that validates a username/pwd against my mongo database and redirects to '/':
app.post('/login', function(req,res) {
let inputUser=req.body.username;
let inputPwd=req.body.password;
findUser({'username':inputUser},function(data){
if ((data[0].srnm===inputUser)&&(data[0].psswd===inputPwd))
{
res.redirect('/');
}
else
{
res.writeHead(200);
res.write(`INVALID USERNAME OR PASSWORD TRY AGAIN OR GO AWAY`);
res.end();
}
});
});
My index.html contains a script.src JS app.
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname+'/index.html'));
});
I want to access an IS_LOGGED_IN flag in this script.
How do I pass the script this information? Do I need to do an AJAX request / put it in a header before my redirect somehow? Or is my approach somehow flawed? Sorry if this is blatantly obvious. I'm very new to node (and also need to learn async.js/promises to avoid callback hell). Thanks.