mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 13:14:06 +01:00
✨ checkToken return user data
This commit is contained in:
parent
19fd29db60
commit
c187c4b7ac
@ -35,3 +35,4 @@ export * from "./Status";
|
|||||||
export * from "./Role";
|
export * from "./Role";
|
||||||
export * from "./User";
|
export * from "./User";
|
||||||
export * from "./VoiceState";
|
export * from "./VoiceState";
|
||||||
|
export * from "./RateLimit";
|
||||||
|
@ -8,14 +8,17 @@ export function checkToken(token: string, jwtSecret: string): Promise<any> {
|
|||||||
jwt.verify(token, jwtSecret, JWTOptions, async (err, decoded: any) => {
|
jwt.verify(token, jwtSecret, JWTOptions, async (err, decoded: any) => {
|
||||||
if (err || !decoded) return rej("Invalid Token");
|
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");
|
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
|
// 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 (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.disabled) return rej("User disabled");
|
||||||
if (user.deleted) return rej("User not found");
|
if (user.deleted) return rej("User not found");
|
||||||
|
|
||||||
return res(decoded);
|
return res({ decoded, user });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user