Refactor user role handling in TRPC context and routers

- Updated the user role property from `rol` to `role` across multiple TRPC context and router files to ensure consistency and clarity in role management.
- Adjusted conditional checks for user roles in various procedures to reflect the updated property name, enhancing code readability and maintainability.
This commit is contained in:
Mauricio Siu
2025-05-04 19:26:09 -06:00
parent c13a68dab4
commit 1c73dab719
12 changed files with 57 additions and 60 deletions

View File

@@ -30,7 +30,7 @@ import { ZodError } from "zod";
*/
interface CreateContextOptions {
user: (User & { rol: "member" | "admin" | "owner"; ownerId: string }) | null;
user: (User & { role: "member" | "admin" | "owner"; ownerId: string }) | null;
session: (Session & { activeOrganizationId: string }) | null;
req: CreateNextContextOptions["req"];
res: CreateNextContextOptions["res"];
@@ -83,7 +83,7 @@ export const createTRPCContext = async (opts: CreateNextContextOptions) => {
? {
...user,
email: user.email,
rol: user.role as "owner" | "member" | "admin",
role: user.role as "owner" | "member" | "admin",
id: user.id,
ownerId: user.ownerId,
}
@@ -180,7 +180,7 @@ export const uploadProcedure = async (opts: any) => {
};
export const cliProcedure = t.procedure.use(({ ctx, next }) => {
if (!ctx.session || !ctx.user || ctx.user.rol !== "owner") {
if (!ctx.session || !ctx.user || ctx.user.role !== "owner") {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
return next({
@@ -194,7 +194,7 @@ export const cliProcedure = t.procedure.use(({ ctx, next }) => {
});
export const adminProcedure = t.procedure.use(({ ctx, next }) => {
if (!ctx.session || !ctx.user || ctx.user.rol !== "owner") {
if (!ctx.session || !ctx.user || ctx.user.role !== "owner") {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
return next({