@fran-834/gs-microservice-core
Version:
Core package for Node.js microservices by Galduria Software. Includes security, logging, validation, and error handling middlewares.
21 lines (20 loc) • 902 B
JavaScript
import { AppError, commonErrors, commonHTTPErrors } from "../helpers/errors/index.js";
const verifyPublicTokenForBooking = (req, res, next) => {
try {
// Check if the token has the required claims for booking access
if (req.module !== "bookings") {
throw new AppError(commonErrors.forbidden, commonHTTPErrors.forbidden, "Forbidden: Invalid module");
}
if (!req.permissions || !req.permissions.includes("read")) {
throw new AppError(commonErrors.forbidden, commonHTTPErrors.forbidden, "Forbidden: Insufficient permissions");
}
if (req.audience !== "web" && req.audience !== "mobile") {
throw new AppError(commonErrors.forbidden, commonHTTPErrors.forbidden, "Forbidden: Invalid audience");
}
next();
}
catch (error) {
next(error);
}
};
export default verifyPublicTokenForBooking;