当我实现会话存储时,一切似乎都运行良好,除了当我关闭浏览器并将其重新连接到connect.sid或会话ID已更改为新的时,强制我的登录系统自动假设用户已注销。我怎样才能确保即使我关闭浏览器,connect.sid在浏览器中保持不变,所以当我访问我的网站时,用户会自动登录?
BOOL loginStatus = [[NSUserDefaults standardUserDefaults] boolForKey:@"isLoggedIn"];
if(loginStatus == NO){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
LoginViewController *loginViewcontroller = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self presentViewController:loginViewcontroller animated:YES completion:nil];
}
会话的依赖关系:
app.use(session({
store: new MongoStore({
mongooseConnection: mongoose.connection,
collection: 'MongoStore',
autoRemove: 'native',
ttl: 14 * 24 * 60 * 60 // 14 days
}),
secret: 'secret',
resave: true,
saveUninitialized: true,
maxAge: null
}))
答案 0 :(得分:0)
通过更改cookie解析器密码以匹配会话密钥,我能够实现我想要的目标。
app.use(cookieParser('secret'));