diff --git a/src/controllers/userController.ts b/src/controllers/userController.ts index 3efb7bc..ae695ef 100644 --- a/src/controllers/userController.ts +++ b/src/controllers/userController.ts @@ -22,7 +22,7 @@ class UserController { static async signup(req: UserInterface, res: Response) { try { const { name, email, password } = req.body; - let uploadedImage: string = null; + let uploadedImage: string |null= null; // CHECK IF REQUIRED FIELDS ARE NOT EMPTY if (!name || !email || !password) { @@ -73,7 +73,7 @@ class UserController { // CREATE TOKEN const token = jwt.sign( { _id: newUser._id, email: newUser?.email /*, role: newUser?.role*/ }, - JWT_SECRET, + JWT_SECRET as jwt.Secret, { expiresIn: "1d" } ); @@ -142,7 +142,7 @@ class UserController { email: userExists?.email, //role: userExists?.role, }, - JWT_SECRET, + JWT_SECRET as jwt.Secret , { expiresIn: "1d" } ); diff --git a/src/middlewares/isAuthenticated.ts b/src/middlewares/isAuthenticated.ts index fd7ab4d..e468868 100644 --- a/src/middlewares/isAuthenticated.ts +++ b/src/middlewares/isAuthenticated.ts @@ -24,7 +24,7 @@ export const isAuthenticated = (req: UserInterface, res: Response, next) => { } try { - const decoded = jwt.verify(token, JWT_SECRET); + const decoded = jwt.verify(token, JWT_SECRET as jwt.Secret); req.user = decoded; next(); } catch (error) { diff --git a/src/routes/blogRoutes.ts b/src/routes/blogRoutes.ts index 8509aab..daec328 100644 --- a/src/routes/blogRoutes.ts +++ b/src/routes/blogRoutes.ts @@ -1,11 +1,11 @@ import express, { Router } from "express"; import BlogController from "../controllers/blogController"; -import { /*isAdmin,*/ isAuthenticated } from "../middlewares/isAuthenticated"; +import { isAdmin, isAuthenticated } from "../middlewares/isAuthenticated"; const router: Router = express.Router(); // CREATE BLOG -router.post("/createNewBlog",/* isAuthenticated, isAdmin,*/ BlogController.createBlog); +router.post("/createNewBlog", isAuthenticated, isAdmin, BlogController.createBlog); // LIST BLOGS router.get("/", BlogController.listBlogs); @@ -14,10 +14,10 @@ router.get("/", BlogController.listBlogs); router.get("/:id", BlogController.getBlog); // DELETE BLOG -router.delete("/:id", isAuthenticated, /*isAdmin,*/ BlogController.deleteBlog); +router.delete("/:id", isAuthenticated, isAdmin, BlogController.deleteBlog); // UPDATE BLOG -router.patch("/:id", isAuthenticated, /*isAdmin,*/ BlogController.updateBlog); +router.patch("/:id", isAuthenticated, isAdmin, BlogController.updateBlog); // LIKE BLOG router.post("/:id/like", isAuthenticated, BlogController.likeBlog);