Answer the question
In order to leave comments, you need to log in
How to work with cookies correctly?
If on the client it is necessary to accompany each action with a check whether there is a session, and it is stored in cookies, then if we say before requesting these protected pages, is it possible to simply write the user-id correspondence from the server once from the server and check the cookie already? that is, the type cookie.user is not empty, then give the page, or do you need to check this correspondence from the server every time?
This is how I check on the server now
if (req.session.user) {
res.json({"login": req.session.user});
}
else{
next();
}
app.use(session({
secret: config.get('session:secret'),
resave: false,
saveUninitialized: true,
name: config.get('session:name'),
path: config.get('session:path'),
httpOnly: config.get('session:httpOnly'),
maxAge: config.get('session:maxAge'),
store: new MongoStore({
host: 'localhost', // Default, optional
port: config.get('mongoose:port'), // Default, optional
db: config.get('mongoose:db') // Required
}),
proxy: true
}));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question