OAuthTokenSchema.statics = {
getByRefreshTokenAndPopulateClient: getByRefreshTokenAndPopulateClient,
getByTokenAndPopulateUser: getByTokenAndPopulateUser,
- getByRefreshToken: getByRefreshToken
+ getByRefreshToken: getByRefreshToken,
+ removeByUserId: removeByUserId
}
mongoose.model('OAuthToken', OAuthTokenSchema)
function getByRefreshToken (refreshToken) {
return this.findOne({ refreshToken: refreshToken }).exec()
}
+
+function removeByUserId (userId, callback) {
+ return this.remove({ user: userId }, callback)
+}
const modelUtils = require('./utils')
const peertubeCrypto = require('../helpers/peertube-crypto')
+const OAuthToken = mongoose.model('OAuthToken')
+
// ---------------------------------------------------------------------------
const UserSchema = mongoose.Schema({
})
})
+UserSchema.pre('remove', function (next) {
+ const user = this
+
+ OAuthToken.removeByUserId(user._id, next)
+})
+
mongoose.model('User', UserSchema)
// ------------------------------ METHODS ------------------------------