Skip to content

Commit

Permalink
Modified the Authentication.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paccyfic committed Mar 20, 2024
1 parent 0669868 commit 249e7cf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/controllers/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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" }
);

Expand Down Expand Up @@ -142,7 +142,7 @@ class UserController {
email: userExists?.email,
//role: userExists?.role,
},
JWT_SECRET,
JWT_SECRET as jwt.Secret ,
{ expiresIn: "1d" }
);

Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/isAuthenticated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/routes/blogRoutes.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 249e7cf

Please sign in to comment.