summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-06-23 18:06:00 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-06-23 18:06:00 +0200
commite3dda743afea2e994c119f492e5e378daa66810b (patch)
treee6636ca5a061e9368fd9db5be47f21fe968459e6 /src/util
parent1.3.16 (diff)
downloadserver-e3dda743afea2e994c119f492e5e378daa66810b.tar.xz
:bug: fix checkToken
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Database.ts1
-rw-r--r--src/util/checkToken.ts3
2 files changed, 2 insertions, 2 deletions
diff --git a/src/util/Database.ts b/src/util/Database.ts
index e5323ed6..3a0f0157 100644
--- a/src/util/Database.ts
+++ b/src/util/Database.ts
@@ -2,7 +2,6 @@ import "./MongoBigInt";
 import mongoose, { Collection, Connection, LeanDocument } from "mongoose";
 import { ChangeStream, ChangeEvent, Long } from "mongodb";
 import EventEmitter from "events";
-import { Document } from "mongoose";
 const uri = process.env.MONGO_URL || "mongodb://localhost:27017/fosscord?readPreference=secondaryPreferred";
 
 // TODO: auto throw error if findOne doesn't find anything
diff --git a/src/util/checkToken.ts b/src/util/checkToken.ts
index 73ffb670..4a60195b 100644
--- a/src/util/checkToken.ts
+++ b/src/util/checkToken.ts
@@ -9,7 +9,8 @@ export function checkToken(token: string, jwtSecret: string): Promise<any> {
 
 			const user = await UserModel.findOne({ id: decoded.id }, { "user_data.valid_tokens_since": true }).exec();
 			if (!user) return rej("Invalid Token");
-			if (decoded.iat * 1000 < user.user_data.valid_tokens_since.getTime()) return rej("Invalid Token");
+			// we need to round it to seconds as it saved as seconds in jwt iat and valid_tokens_since is stored in milliseconds
+			if (decoded.iat * 1000 < user.user_data.valid_tokens_since.setSeconds(0, 0)) return rej("Invalid Token");
 			if (user.disabled) return rej("User disabled");
 			if (user.deleted) return rej("User not found");