From c187c4b7ac919f0f79afe965bf776bf4ee385493 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Wed, 30 Jun 2021 21:56:25 +0200 Subject: [PATCH] :sparkles: checkToken return user data --- src/models/index.ts | 1 + src/util/checkToken.ts | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/models/index.ts b/src/models/index.ts index 004095db..4cc6ec2b 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -35,3 +35,4 @@ export * from "./Status"; export * from "./Role"; export * from "./User"; export * from "./VoiceState"; +export * from "./RateLimit"; diff --git a/src/util/checkToken.ts b/src/util/checkToken.ts index d890e0e1..e021a406 100644 --- a/src/util/checkToken.ts +++ b/src/util/checkToken.ts @@ -8,14 +8,17 @@ export function checkToken(token: string, jwtSecret: string): Promise { 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(); + const user = await UserModel.findOne( + { id: decoded.id }, + { "user_data.valid_tokens_since": true, bot: true } + ).exec(); if (!user) 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"); - return res(decoded); + return res({ decoded, user }); }); }); }