我想知道我是否可以通过相同的req.cart
方法获得与用户相关但存储在不同数据库中的req.inventory
或.deserializeUser
等其他内容?
答案 0 :(得分:1)
您可以为此定义自定义中间件。演示代码:
// ...
app.use(passport.initialize());
app.use(passport.session());
app.use(function(req, res, next) {
// the use logged in.
if (req.isAuthenticated()) {
// Fetch the user information from other databases by `req.user.id`.
// Store the returned information as `req.cart` and `req.inventory` separately.
};
next();
});