@@ -293,13 +293,23 @@ module.exports = function(User) {
293293
294294 User . logout = function ( tokenId , fn ) {
295295 fn = fn || utils . createPromiseCallback ( ) ;
296- this . relations . accessTokens . modelTo . findById ( tokenId , function ( err , accessToken ) {
296+
297+ if ( ! tokenId ) {
298+ var err = new Error ( g . f ( '{{accessToken}} is required to logout' ) ) ;
299+ err . status = 401 ;
300+ process . nextTick ( function ( ) { fn ( err ) ; } ) ;
301+ return fn . promise ;
302+ }
303+
304+ this . relations . accessTokens . modelTo . destroyById ( tokenId , function ( err , info ) {
297305 if ( err ) {
298306 fn ( err ) ;
299- } else if ( accessToken ) {
300- accessToken . destroy ( fn ) ;
307+ } else if ( 'count' in info && info . count === 0 ) {
308+ err = new Error ( g . f ( 'Could not find {{accessToken}}' ) ) ;
309+ err . status = 401 ;
310+ fn ( err ) ;
301311 } else {
302- fn ( new Error ( g . f ( 'could not find {{accessToken}}' ) ) ) ;
312+ fn ( ) ;
303313 }
304314 } ) ;
305315 return fn . promise ;
@@ -743,10 +753,10 @@ module.exports = function(User) {
743753 {
744754 description : 'Logout a user with access token.' ,
745755 accepts : [
746- { arg : 'access_token' , type : 'string' , required : true , http : function ( ctx ) {
756+ { arg : 'access_token' , type : 'string' , http : function ( ctx ) {
747757 var req = ctx && ctx . req ;
748758 var accessToken = req && req . accessToken ;
749- var tokenID = accessToken && accessToken . id ;
759+ var tokenID = accessToken ? accessToken . id : undefined ;
750760 return tokenID ;
751761 } , description : 'Do not supply this argument, it is automatically extracted ' +
752762 'from request headers.' ,
0 commit comments