refactor(v1 middle ware): removed the need for this and just let it all pass
This commit is contained in:
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user