Expired accessToken are not removed from the table automatically.
When I use MySQL data source, expired accessToken are not removed from the table automatically.
Is this a database connector issue or a usage issue ? normally accessTokens are destroyed on logout or when trying to use an expired accessToken on a API call. (see functions User.logout and AccessToken.prototype.validate) With a web frontend it is not guaranteed that the user logs out or uses the accessToken until it expires. You could do a validate on the related accessTokens in the User.afterRemote('login',function (ctx, token, next){...}) so expired tokens are destroyed after each login
Thank you for your reply. I did not connect other data source but I do not think it is a database connector issue. So I have to write the code of destroying the expired accessToken in the User.afterRemote('login'), how to write the validation condition?
The validate function is already implemented in accessToken.
User.afterRemote('login', function (ctx, token, next) {
User.findById(token.userId,function(err,user){
if(!err && user) {
var destroyedCount = 0;
var validCount = 0;
user.accessTokens(function (err, accessTokens) {
accessTokens.forEach(function (accessToken) {
accessToken.validate(function (err, isValid){
if(isValid) validCount++;
else
destroyedCount++;
})
});
console.log('AccessTokens: valid: %d, destroyed: %d',validCount,destroyedCount);
});
}
});
next();
});