summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-24 19:32:35 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-24 19:32:35 +0200
commit1ba36abdf07dd32514d1adae1669b842dcb55a06 (patch)
tree873e816483b7a75b32860ca97f0f87c8d56c9394 /src/util
parent1.3.1 (diff)
downloadserver-1ba36abdf07dd32514d1adae1669b842dcb55a06.tar.xz
additional token checks: user disabled/deleted or if the token was revoked
Diffstat (limited to 'src/util')
-rw-r--r--src/util/checkToken.ts9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/util/checkToken.ts b/src/util/checkToken.ts
index 80896de7..1a52b5b9 100644
--- a/src/util/checkToken.ts
+++ b/src/util/checkToken.ts
@@ -1,11 +1,18 @@
 import { JWTOptions } from "./Constants";
 import jwt from "jsonwebtoken";
+import { UserModel } from "../models";
 
 export function checkToken(token: string, jwtSecret: string): Promise<any> {
 	return new Promise((res, rej) => {
-		jwt.verify(token, jwtSecret, JWTOptions, (err, decoded: any) => {
+		jwt.verify(token, jwtSecret, JWTOptions, async (err, decoded: any) => {
 			if (err || !decoded) return rej("Invalid Token");
 
+			const user = await UserModel.findOne({ id: decoded.id }, { "user_data.valid_tokens_since": true }).exec();
+			if (!user) return rej("User not found");
+			if (decoded.iat * 1000 < user.user_data.valid_tokens_since.getTime()) return rej("Invalid Token");
+			if (user.disabled) return rej("User disabled");
+			if (user.deleted) return rej("User not found");
+
 			return res(decoded);
 		});
 	});