Просмотр исходного кода

Update access token model to use inclusive expiration checks

reiji-h 1 год назад
Родитель
Сommit
d6930df967
1 измененных файлов с 4 добавлено и 4 удалено
  1. 4 4
      apps/app/src/server/models/access-token.ts

+ 4 - 4
apps/app/src/server/models/access-token.ts

@@ -96,24 +96,24 @@ accessTokenSchema.statics.deleteAllTokensByUserId = async function(userId: Types
 
 
 accessTokenSchema.statics.deleteExpiredToken = async function() {
 accessTokenSchema.statics.deleteExpiredToken = async function() {
   const now = new Date();
   const now = new Date();
-  await this.deleteMany({ expiredAt: { $lte: now } });
+  await this.deleteMany({ expiredAt: { $lt: now } });
 };
 };
 
 
 accessTokenSchema.statics.findUserIdByToken = async function(token: string) {
 accessTokenSchema.statics.findUserIdByToken = async function(token: string) {
   const tokenHash = generateTokenHash(token);
   const tokenHash = generateTokenHash(token);
   const now = new Date();
   const now = new Date();
-  return this.findOne({ tokenHash, expiredAt: { $gt: now } }).select('user');
+  return this.findOne({ tokenHash, expiredAt: { $gte: now } }).select('user');
 };
 };
 
 
 accessTokenSchema.statics.findTokenByUserId = async function(userId: Types.ObjectId | string) {
 accessTokenSchema.statics.findTokenByUserId = async function(userId: Types.ObjectId | string) {
   const now = new Date();
   const now = new Date();
-  return this.find({ user: userId, expiredAt: { $gt: now } }).select('_id expiredAt scope description');
+  return this.find({ user: userId, expiredAt: { $gte: now } }).select('_id expiredAt scope description');
 };
 };
 
 
 accessTokenSchema.statics.validateTokenScopes = async function(token: string, requiredScopes: string[]) {
 accessTokenSchema.statics.validateTokenScopes = async function(token: string, requiredScopes: string[]) {
   const tokenHash = generateTokenHash(token);
   const tokenHash = generateTokenHash(token);
   const now = new Date();
   const now = new Date();
-  const tokenData = await this.findOne({ tokenHash, expiredAt: { $gt: now }, scope: { $all: requiredScopes } });
+  const tokenData = await this.findOne({ tokenHash, expiredAt: { $gte: now }, scope: { $all: requiredScopes } });
   return tokenData != null;
   return tokenData != null;
 };
 };