Chat is working
[vchess.git] / server / utils / access.js
index 20f3f79..11753a0 100644 (file)
@@ -6,7 +6,7 @@ module.exports =
        logged: function(req, res, next) {
                const callback = () => {
                        if (!loggedIn)
-                               return res.redirect("/");
+                               return res.json({errmsg: "Not logged in"});
                        next();
                };
                let loggedIn = undefined;
@@ -42,13 +42,13 @@ module.exports =
                // 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();
        },