const router = useRouter();const { categoryId } = router.query; const { data: categoryProducts, isFetched } = api.category.getCategoryItems.useQuery( { name: categoryId as string[] }, { enabled: router.isReady, refetchOnWindowFocus: false }, )
export const userRouter = createRouter().mutation("login", { input: z.object({ email: z.string(), password: z.string(), }), async resolve({ ctx , input}) { // @ts-ignore const user = await ctx.prisma.user.findUniqueOrThrow({ where: { email: input.email, } }) if (!user) { throw new TRPCError({ code: 'NOT_FOUND', message: 'User not found' }) } const isMatch = await bcrypt.compare(input.password, user.password); if (!isMatch) { throw new TRPCError({ code: 'UNAUTHORIZED', message: 'Incorrect Credentials' }) } return { user: user, message: "Login Successful" }; }})