user1400312
user1400312

Reputation:

Best way to display an error Express, Jade and Mongo

What is the best way to pass a warning message through to a view with Express & Jade?

I have created a login system that checks a password entered against one stored within the Mongo Database, it then sets a cookie and redirects, or just redirects if it's incorrect.

if(obj.password === req.body.loginPassword){
     res.cookie('username', req.body.loginUsername);
     red.redirect('/')
}else{
     res.redirect('/');
}

I'd like to pass a warning message via the else on a failed login to the view.

Upvotes: 2

Views: 1301

Answers (1)

luin
luin

Reputation: 1995

Express 3.0:

You can use req.session to store the error message or check out this middleware for simple: https://github.com/jaredhanson/connect-flash

Express 2.0:

You can use req.flash directly. The usage described in http://expressjs.com/2x/guide.html

Upvotes: 3

Related Questions