Migrated the authenticate.ts middleware

This commit is contained in:
Mathias Wagner 2023-11-07 09:16:33 +01:00
parent 0d83a0f670
commit 51e7b2562d
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -18,11 +18,11 @@ module.exports.authenticate = async (req: AuthenticatedRequest, res: Response, n
if (splitHeader.length !== 2) return res.status(400).json({message: "You need to provide the token in the 'authorization' header"});
// Check if the provided token is wrong
req.token = await Token.findOne({token: splitHeader[1]}).exec() as IToken;
req.token = await Token.findOne({where: {token: splitHeader[1]}}) as IToken;
if (req.token == null) return res.status(401).json({message: "The provided token is wrong"});
// Check if the provided user exists
req.user = await User.findOne({clientId: req.token.clientId}) as IUser;
req.user = await User.findOne({where: {clientId: req.token.clientId}}) as IUser;
if (req.user == null) return res.status(401).json({message: "The provided token is wrong"});
next();