My code:
module.exports = async (req, res, next) => {
const redirectURL = ((req.originalUrl.includes("login") || req.originalUrl === "/") ? "/selector" : req.originalUrl);
if(req.session.user){
return next();
} else {
const state = Math.random().toString(36).substring(5);
req.client.states[state] = redirectURL;
return res.redirect(`/api/login?state=${state}`);
}
};
Give me this error:
Cannot set properties of undefined (setting 'yhgrz0jg')
Can anyone help me I've tried everything and I can't solve it?
CodePudding user response:
req.client.states
is undefined, that's why you're getting error. Why are you setting it anyway, since you're not using that value anywhere later on?