refactor(v1 middle ware): removed the need for this and just let it all pass

This commit is contained in:
2025-10-28 07:41:34 -05:00
parent cc3657f66f
commit 8f22165951
2 changed files with 27 additions and 27 deletions

View File

@@ -5,18 +5,18 @@ import jwt from "jsonwebtoken";
const { sign, verify } = jwt;
export const authMiddleware: MiddlewareHandler = async (c, next) => {
console.log("middleware checked");
const cookieHeader = c.req.header("Cookie");
if (!cookieHeader) return c.json({ error: "Unauthorized" }, 401);
// console.log("middleware checked");
// const cookieHeader = c.req.header("Cookie");
// if (!cookieHeader) return c.json({ error: "Unauthorized" }, 401);
const res = await axios.get(`${process.env.LST_BASE_URL}/api/user/me`, {
headers: { Cookie: cookieHeader },
});
// const res = await axios.get(`${process.env.LST_BASE_URL}/api/user/me`, {
// headers: { Cookie: cookieHeader },
// });
if (res.status === 401) return c.json({ error: "Unauthorized" }, 401);
// if (res.status === 401) return c.json({ error: "Unauthorized" }, 401);
//const user = await resp.json();
c.set("user", res.data.user);
// //const user = await resp.json();
// c.set("user", res.data.user);
return next();
};

View File

@@ -84,26 +84,26 @@ interface UserRole {
const hasCorrectRole = (requiredRole: string[], module: string) =>
createMiddleware(async (c, next) => {
const cookieHeader = c.req.header("Cookie");
if (!cookieHeader) return c.json({ error: "Unauthorized" }, 401);
// const cookieHeader = c.req.header("Cookie");
// if (!cookieHeader) return c.json({ error: "Unauthorized" }, 401);
const res = await axios.get(`${process.env.LST_BASE_URL}/api/user/roles`, {
headers: { Cookie: cookieHeader },
});
// const res = await axios.get(`${process.env.LST_BASE_URL}/api/user/roles`, {
// headers: { Cookie: cookieHeader },
// });
const currentRoles: UserRole[] = res.data.data;
const canAccess = currentRoles.some(
(r) => r.module === module && requiredRole.includes(r.role),
);
if (!canAccess) {
return c.json(
{
error: "Unauthorized",
message: `You do not have access to ${module}`,
},
400,
);
}
// const currentRoles: UserRole[] = res.data.data;
// const canAccess = currentRoles.some(
// (r) => r.module === module && requiredRole.includes(r.role),
// );
// if (!canAccess) {
// return c.json(
// {
// error: "Unauthorized",
// message: `You do not have access to ${module}`,
// },
// 400,
// );
// }
return next();
});