sommeeeR
sommeeeR
TtRPC
Created by sommeeeR on 11/28/2023 in #❓-help
I want to refetch and set the inital data of an useState
Hello guys, currently i am retrieving the data i use in useState with SSR, but i want to use somethinng that makes it possible to update the useState on interactions from the user. Im guessing I should use useQuery?
How can i set it so initialData in my useState works. this is my current useState line:
const [items, setItems] = useState(cat.CatImage);
const [items, setItems] = useState(cat.CatImage);
6 replies
TtRPC
Created by sommeeeR on 11/3/2023 in #❓-help
Check if Role is ADMIN
Hey guys I have a private procedure in T3 Stack. I need to check if the user thats doing the action is indeed admin. How can i implement that in this privateProcedure?
import { z } from "zod";

import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";
import { db } from "~/server/db";

export const userRouter = createTRPCRouter({
delete: protectedProcedure.input(z.string()).mutation(async ({ input }) => {
const msg = await db.user.findFirst({ where: { id: input } });
if (!msg) {
return { success: false, msg: "User not found" };
}
await db.user.delete({ where: { id: input } });
return { success: true, msg };
}),
});
import { z } from "zod";

import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";
import { db } from "~/server/db";

export const userRouter = createTRPCRouter({
delete: protectedProcedure.input(z.string()).mutation(async ({ input }) => {
const msg = await db.user.findFirst({ where: { id: input } });
if (!msg) {
return { success: false, msg: "User not found" };
}
await db.user.delete({ where: { id: input } });
return { success: true, msg };
}),
});
3 replies