Skip to content

Commit

Permalink
🐳 chore(middlewares): authorize permission
Browse files Browse the repository at this point in the history
  • Loading branch information
EvandroCalado committed Feb 23, 2024
1 parent c6637f1 commit 11f0810
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion middlewares/authMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { UnauthenticatedError } from "../errors/customErrors.js";
import {
UnauthenticatedError,
UnauthorizedError,
} from "../errors/customErrors.js";
import { verifyJwt } from "../utils/token.js";

const authenticateUser = (req, res, next) => {
Expand All @@ -20,3 +23,13 @@ const authenticateUser = (req, res, next) => {
};

export default authenticateUser;

export const authorizePermissions = (...roles) => {
return (req, res, next) => {
if (!roles.includes(req.user.role)) {
throw new UnauthorizedError("unauthorized to access this route");
}

next();
};
};

0 comments on commit 11f0810

Please sign in to comment.