handle no token in a productive way

This commit is contained in:
Ryan Tharp 2020-07-21 09:42:08 +00:00
parent 9cd82b4b74
commit a3e9d1a9f0
1 changed files with 10 additions and 2 deletions

View File

@ -27,7 +27,15 @@ function sendResponse(json, resp) {
function validUser(token, res, cb) {
return new Promise(function(resolve, rej) {
if (!token) {
return resolve(false);
console.error('lib.dialect::validUser - getUserClientByToken - no token', token);
const resObj={
meta: {
code: 401,
error_message: 'Authorization required'
}
};
sendResponse(resObj, res);
return resolve();
}
dispatcher.getUserClientByToken(token, (err, usertoken) => {
if (err) {
@ -38,10 +46,10 @@ function validUser(token, res, cb) {
error_message: err
}
};
console.error('lib.dialect::validUser - error trying to verify token:', token);
sendResponse(resObj, res);
return resolve();
}
//console.log('lib.dialect::validUser - usertoken', JSON.parse(JSON.stringify(usertoken)))
if (usertoken === null) {
// could be they didn't log in through a server restart
const resObj={