我正在将两个小应用程序合并为一个,应该通过两个子域进行访问。为此,我使用模块“express-subdomain”。我正在尝试使用Passport,因此当用户登录第一个应用程序时,他会在两个应用程序中登录。但是使用req.isAuthenticated()
我确实可以在“第一个”应用程序中登录,但之后我不在“第二个”应用程序中。
我正在寻找在第一个子域中进行护照验证并在第二个子域中登录的任何解决方案,包括在需要时保留两个不同的应用程序。
假设护照已正确配置为本地策略,以及路由器和应用程序的其余部分。这是它的样子:
app.js
// <- requires etc
var passport = require('./configurePassport.js')(require('passport'));
var app = express();
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(expressSession({
secret: 'bestSecretEver',
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
// and others
var firstRouter = express.Router();
firstRouter.use('/public', express.static(__dirname + '/first/public'));
firstRouter.use(favicon(__dirname + '/first/public/favicon.ico'));
// <- setting first router's GET, POST etc
app.use(subdomain('sub1', firstRouter)); // for sub1.example.com
var secondRouter = express.Router();
secondRouter.use('/public', express.static(__dirname + '/second/public'));
secondRouter.use(favicon(__dirname + '/second/public/favicon.ico'));
// <- setting second router's GET, POST etc
app.use(subdomain('sub2', secondRouter)); // for sub2.example.com
有什么想法吗?
答案 0 :(得分:0)
查看您为保存身份验证而保存Cookie的位置。确保将其保存到根域。即:*.example.com
而非sub1.example.com