简体   繁体   中英

express-session vs passport.js?

I am currently implementing email-password login functionality for a website using just express-session. Everywhere I look I see people using passport.js to authenticate requests. The below code is working for me.

app.post("/signup", function(req, res) {
    var user = new userModel(req.body);
    user.save();
    req.session.userid = user.id; // I use this id to authenticate
}

Do I have any reason to use passport?

In NodeJS, you can authenticate in 2 ways:

  1. Session-Based authentication

  2. Token-Based authentication

Passport is a token-based authentication system. It uses JSON web token ie jwt.

In your case, as you are using session-based authentication you need not use passport

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM