使用 nodejs、expressjs 和 reactjs 在会话超时后重定向到登录页面
Redirect to login page after session timeout using nodejs, expressjs and reactjs
我有节点和反应应用程序。对于中间件,我正在使用 expressjs。
我正在尝试在会话超时后重定向到登录页面。我正在使用 express-session
进行身份验证,我能够获得会话超时但无法重定向到登录页面。
我的登录 url 是 http://localhost:8009/login
,它是在 ui 部分的 React js 中实现的。
app.use('/', login);
节点和expressjs中的路由器
下面是我的代码。
var session = require('express-session');
app.use(session({
secret: 'Test Service',
name: "test",
saveUninitialized: true,
resave:false,
cookie: {
//maxAge: 24 * 60 * 60 * 1000,
path: '/login',
maxAge: 1 * 10 * 60 * 1000,
overwrite: false
}
}));
谁能帮我解决这个问题。
我也检查了下面 urls 但无法获得解决方案。
How to keep the session active when redirecting from domain to subdomain in Express js/
https://gitlab.com/dinh.dich/express-session-expire-timeout#README
在我看来,您有两个选择
1 - 如果您正在谈论会话并在没有会话时重定向:
在您的路由器中创建一个函数:
module.exports.home = (req,res)=>{
if(!req.session.user){
//index is the main page without any session
res.render('index');
}
else{
//render to a different page
}
};
希望这会给你一个更好的主意。祝你好运!
我有节点和反应应用程序。对于中间件,我正在使用 expressjs。
我正在尝试在会话超时后重定向到登录页面。我正在使用 express-session
进行身份验证,我能够获得会话超时但无法重定向到登录页面。
我的登录 url 是 http://localhost:8009/login
,它是在 ui 部分的 React js 中实现的。
app.use('/', login);
节点和expressjs中的路由器
下面是我的代码。
var session = require('express-session');
app.use(session({
secret: 'Test Service',
name: "test",
saveUninitialized: true,
resave:false,
cookie: {
//maxAge: 24 * 60 * 60 * 1000,
path: '/login',
maxAge: 1 * 10 * 60 * 1000,
overwrite: false
}
}));
谁能帮我解决这个问题。 我也检查了下面 urls 但无法获得解决方案。
How to keep the session active when redirecting from domain to subdomain in Express js/ https://gitlab.com/dinh.dich/express-session-expire-timeout#README
在我看来,您有两个选择
1 - 如果您正在谈论会话并在没有会话时重定向:
在您的路由器中创建一个函数:
module.exports.home = (req,res)=>{
if(!req.session.user){
//index is the main page without any session
res.render('index');
}
else{
//render to a different page
}
};
希望这会给你一个更好的主意。祝你好运!