UP checkAuthenticated.js -> ts

This commit is contained in:
Nikola Petrov
2024-07-16 14:24:01 +02:00
parent 9452dcf90e
commit c5b2e2d82b
6 changed files with 21 additions and 7 deletions

View File

@@ -0,0 +1,20 @@
import { type Express, type NextFunction, type Request, type Response } from "express";
import UserModel from '../models/userModel';
async function checkAuthenticated(req: Request, res: Response, next: NextFunction) {
try {
const password = req.body.pass;
const userFound = await UserModel.findOne({ pass: password });
if (!userFound) {
return res.status(404).json({ message: 'Wrong password' });
}
req.user = userFound;
return next();
} catch (err) {
console.log(err);
return res.status(500).json({ message: 'Error when getting transactions.' });
}
}
export default checkAuthenticated;

13
miscellaneous/custom.d.ts vendored Normal file
View File

@@ -0,0 +1,13 @@
declare namespace Express {
export interface Request {
user?: Document<unknown, {}, {
pass?: string | undefined;
omdb_key?: string | undefined;
twitch_client_id?: string | undefined;
twitch_client_secret?: string | undefined;
mac_address?: string | undefined;
}>
}
}