我正在尝试学习如何使用stormpath和express节点制作多租户应用程序。这是关于该主题的官方文档。至于现在我正在使用express-stormpath库来进行登录和其他操作。但我找不到我是如何做多租户的。
更新 我让它与护照风暴路径策略一起使用。我不知道这是否是正确的方法,但它有效......现在的问题是我如何在快速版本中更改 accountStore 动态?感觉像一个公共声明的变量不是那么好?
var href = {
href: null
}
function hrefUrl(req, res, next){
var host = req.headers.host;
var account = host.split(".")[0];
spClient.getDirectories(function (err, directories) {
directories.each(function (dir, cb){
if(account.toLowerCase() == dir.name.toLowerCase()){
href.href = dir.href
}
cb();
}, function (err){
if(href.href == null){
return res.redirect(301, 'http://dashboard.local.dev/selectCompany');
}
next();
});
});
}
// Authenticate a user.
router.post('/login', hrefUrl, passport.authenticate('stormpath',
{
successRedirect: '/dashboard',
failureRedirect: '/login',
failureFlash: 'Invalid email or password.',
accountStore: href
}
)
);