I want to create a login system, using Node JS and ExpressJS. The user types their credentials, then the server checks these to see if they are valid. If they are valid, the server will redirect the user the home page and send along data, including the user's credentials (for further use). This is RESTful.
const app = require("express")();
const bodyParser = require('body-parser');
app.get("/login", function(req, res)
{
res.sendFile(__dirname + "/front-end/login.html");
});
app.post("/login",function(req, res)
{
var username = req.body.username;
var password = req.body.password;
//returns whether the credentials work
var credentialsPassed = checkCredentials(username,password);
if(credentialsPassed)
{
//redirect to home-page and pass along the user's credentials for further use
}
});
I already read How do I redirect in expressjs while passing some context?. The answer sends data in the url. However, I need to send the user's credentials, so it would be insecure to pass it in the URL. The other alternative is to use EJS (or something similar), but I would have to download a pretty big module just for this 1 task.
Is there any better way?