salix/back/methods/account/validate-token.js

32 lines
844 B
JavaScript

module.exports = Self => {
Self.remoteMethod('validateToken', {
description: 'Get the user information and permissions',
accepts: [
{
arg: 'token',
type: 'String',
description: 'The token to validate',
required: true
}
],
returns: {
type: 'Boolean',
root: true
},
http: {
path: `/validateToken`,
verb: 'GET'
}
});
Self.validateToken = function(tokenId, cb) {
Self.app.models.AccessToken.findById(tokenId, (err, token) => {
if (err) return cb(err);
if (token)
token.validate((_, isValid) => cb(null, isValid === true));
else
cb(null, false);
});
};
};