UNPKG

alapa

Version:

A cutting-edge web development framework designed to revolutionize the way developers build modern web applications.

45 lines (44 loc) 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bearerAuth = void 0; const utils_1 = require("../../../utils"); const api_1 = require("../../../api"); const bearerAuth = async (req, res, next) => { // Authenticate using Bearer token if (req.headers.authorization && req.headers.authorization.startsWith("Bearer ")) { const token = req.headers.authorization.split(" ")[1]; try { const payload = await api_1.JWT.verifyToken(token); // const checkAuth = await UserAuthController.verifyPayload(payload); if (payload) { req.auth.api.bearerToken = token; // req.auth.api.jwtPayload = payload; next(); } else { return res.api({ code: 401, status: "error", message: "Unauthorized: Bearer token is invalid", }); } } catch (error) { utils_1.Logger.error(error); return res.api({ code: 401, status: "error", message: "Unauthorized: Invalid or expired token", }); } } else { return res.api({ code: 401, status: "error", message: "Unauthorized: Bearer Authentication is required for this operation", }); } }; exports.bearerAuth = bearerAuth;