Maj
Maj
TtRPC
Created by puzzles9351 on 6/23/2023 in #❓-help
useQuery with query params
This is how i use it.
4 replies
TtRPC
Created by puzzles9351 on 6/23/2023 in #❓-help
useQuery with query params
const router = useRouter();
const { categoryId } = router.query;
const { data: categoryProducts, isFetched } = api.category.getCategoryItems.useQuery(
{ name: categoryId as string[] },
{ enabled: router.isReady, refetchOnWindowFocus: false },
)
const router = useRouter();
const { categoryId } = router.query;
const { data: categoryProducts, isFetched } = api.category.getCategoryItems.useQuery(
{ name: categoryId as string[] },
{ enabled: router.isReady, refetchOnWindowFocus: false },
)
4 replies
TtRPC
Created by puzzles9351 on 6/23/2023 in #❓-help
useQuery with query params
u can do enabled: router.isReady
4 replies
TtRPC
Created by Maj on 6/9/2023 in #❓-help
trpc with app dir nextjs
Thank you.
11 replies
TtRPC
Created by Maj on 6/9/2023 in #❓-help
trpc with app dir nextjs
👍🙏
11 replies
TtRPC
Created by Maj on 6/9/2023 in #❓-help
trpc with app dir nextjs
Thankls.
11 replies
TtRPC
Created by 𝛈𝞂𝗿𝞈𝒆𝒈𝖏𝝰𝛈 𝐜0𝟃3𝗿 on 5/24/2023 in #❓-help
useEffect and useMutation error about conditional rendering of hooks
For me calling the useQuery hook in useEffect is not possible i get an error instantly
11 replies
TtRPC
Created by Maj on 5/24/2023 in #❓-help
useQuery hook modify data on fetch.
its probably not really efficient but im learning for now
5 replies
TtRPC
Created by Maj on 5/24/2023 in #❓-help
useQuery hook modify data on fetch.
Thank you but i managed to parse it on the frontend 🤷‍♂️
5 replies
TtRPC
Created by Maj on 5/24/2023 in #❓-help
useQuery hook modify data on fetch.
also why does my app refetch data from the server everytime i tab out of the browser window and tab back in?.
5 replies
TtRPC
Created by Maj on 11/8/2022 in #❓-help
First time learning trpc really good tool. help with setting cookies on front end.
this is my login router which i want to use to login through and i want to return a cookie and send some data back to the client.
4 replies
TtRPC
Created by Maj on 11/8/2022 in #❓-help
First time learning trpc really good tool. help with setting cookies on front end.
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"
};

}
})
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"
};

}
})
4 replies