app.use
app.js で条件付きで使用することは可能ですか? Express cookie-sessionは動的に値を変更するmaxAge
ことはできず、この種のことを考えていましたが、いくつかのエラーが発生しています:
app.use(function(req,res,next ){
if(typeof req.session == 'undefined' || req.session.staySignedIn === 'undefined'){
//removing cookie at the end of the session
cookieSession({
httpOnly: true,
secure: false,
secureProxy: true,
keys: ['key1', 'key2']
});
}else{
//removing cookie after 30 days
cookieSession({
maxAge: 30*24*60*60*1000, //30 days
httpOnly: true,
secure: false,
secureProxy: true,
keys: ['key1', 'key2']
});
}
next();
});
通常の使用の代わりに:
app.use(cookieSession({
httpOnly: true,
secure: false,
secureProxy: true,
keys: ['key1', 'key2']
}));
現在、次のエラーが発生しています。
未定義のプロパティ「ユーザー」を読み取ることができません
この行を参照していると思います(ただし、正確な場所はわかりません)
req.session.user;