+router.get("/whoami", access.ajax, (req,res) => {
+ const callback = (user) => {
+ return res.json({
+ name: user.name,
+ email: user.email,
+ id: user.id,
+ notify: user.notify,
+ });
+ };
+ const anonymous = {name:"", email:"", id:0, notify:false};
+ console.log(req.cookies); //TODO: cookie not found after authenticate ?
+ if (!req.cookies.token)
+ return callback(anonymous);
+ UserModel.getOne("sessionToken", req.cookies.token, function(err, user) {
+ if (!!err || !user)
+ callback(anonymous);
+ else (!!user)
+ callback(user);
+ });
+});
+