trpc: check unlimited in middleware

This commit is contained in:
vchikalkin 2023-03-29 15:10:34 +03:00
parent 1ea11f8eff
commit 90c0ef481b

View File

@ -25,9 +25,17 @@ export const userMiddleware = t.middleware(async ({ ctx, next }) => {
}, },
}); });
const unlimited = systemuser?.roles?.some((x) => x?.name && unlimitedRoles.includes(x.name));
if (!unlimited) {
throw new TRPCError({
code: 'UNAUTHORIZED',
});
}
return next({ return next({
ctx: { ctx: {
unlimited: systemuser?.roles?.some((x) => x?.name && unlimitedRoles.includes(x.name)), unlimited,
}, },
}); });
}); });