dockerized the project for dev

This commit is contained in:
QkoSad
2024-09-06 16:27:48 +03:00
parent 8e83b6b8df
commit 04ae8b7be8
47 changed files with 363 additions and 635 deletions
+34
View File
@@ -0,0 +1,34 @@
import config from 'config'
import jwt from 'jsonwebtoken'
import type { Request, Response, NextFunction } from 'express';
interface ResponseAndUser extends Request { user?: string }
function auth(req: ResponseAndUser, res: Response, next: NextFunction) {
// Get token from header
const token = req.header('x-auth-token');
// Check if not token
if (!token) {
return res.status(401).json({ msg: 'No token, authorization denied' });
}
// Verify token
try {
jwt.verify(token, config.get('jwtSecret'), (error, decoded) => {
if (error) {
return res.status(401).json({ msg: 'Token is not valid' });
} else {
if (decoded && typeof decoded !== "string")
req.user = decoded?.user;
next();
}
});
} catch (err) {
console.error('something wrong with auth middleware');
res.status(500).json({ msg: 'Server Error' });
}
};
export default auth
+10
View File
@@ -0,0 +1,10 @@
import mongoose from "mongoose";
// middleware to check for a valid object id
import type { Request, Response, NextFunction } from "express";
const checkObjectId = (idToCheck: string) => (req: Request, res: Response, next: NextFunction) => {
if (!mongoose.Types.ObjectId.isValid(req.params[idToCheck]))
return res.status(400).json({ msg: 'Invalid ID' });
next();
};
export default checkObjectId