logged: function(req, res, next) {
const callback = () => {
if (!loggedIn)
- return res.redirect("/");
+ return res.json({errmsg: "Not logged in"});
next();
};
let loggedIn = undefined;
{
// Token in cookies presumably wrong: erase it
res.clearCookie("token");
- res.clearCookie("id");
- res.clearCookie("name");
loggedIn = false;
}
callback();
// Just a quick heuristic, which should be enough
const loggedIn = !!req.cookies.token;
if (loggedIn)
- return res.redirect("/");
+ return res.json({errmsg: "Already logged in"});
next();
},
// Prevent direct access to AJAX results
ajax: function(req, res, next) {
- if (!req.xhr)
+ if (!req.xhr)
return res.json({errmsg: "Unauthorized access"});
next();
},