我当前正在使用passport会话对请求访问我的端点的用户进行身份验证。下面是我的代码片段
const express = require('express');
const app = express();
const session = require('express-session');
const redis = require('redis');
const redisStore = require('connect-redis')(session);
const redisClient = redis.createClient({
host: 'localhost',
port: 6379
});
const passport = require('passport');
const sessionStore = new redisStore({
client: redisClient
})
require('./Services/passport');
app.use(session({
store: sessionStore,
secret: process.env.SESSION_KEY,
resave: false,
cookie: {
secure: false,
maxAge: 60 * 24 * 60 * 60 * 1000,
httpOnly: true,
signed: true
}, // Set to secure:false and expire in 1 minute for demo purposes
saveUninitialized: true
}))
app.use(passport.initialize());
app.use(passport.session());
我正在使用以下代码验证我的端点
app.get('/home',function(req,res){
if (req.isAuthenticated()){
console.log("Auth")
}else{
console.log("not)
}
})
如果我访问我的“home”端点,即使我的本地计算机上没有运行redis,也会打印“auth”。我想问的是这是预期的行为。我知道passport将sessionid存储在cookie中,但当调用req.isAuthentied()方法时,它不应该从redis检索会话信息
暂无答案!
目前还没有任何答案,快来回答吧!