Error on Router

import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

export const postsCreateUser = createTRPCRouter({
checkUser: publicProcedure.query(async (userEmail) => {
const user = await prisma.users.create({
data: {
email: userEmail,
},
});
return user;
}),
});
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

export const postsCreateUser = createTRPCRouter({
checkUser: publicProcedure.query(async (userEmail) => {
const user = await prisma.users.create({
data: {
email: userEmail,
},
});
return user;
}),
});
Type 'ResolveOptions<{ _config: RootConfig<{ ctx: { prisma: PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>; }; meta: object; errorShape: { ...; }; transformer: typeof SuperJSON; }>; ... 5 more ...; _meta: object; }>' is not assignable to type 'string'.ts(2322)
index.d.ts(1825, 5): The expected type comes from property 'email' which is declared here on type '(Without<UsersCreateInput, UsersUncheckedCreateInput> & UsersUncheckedCreateInput) | (Without<...> & UsersCreateInput)'
Type 'ResolveOptions<{ _config: RootConfig<{ ctx: { prisma: PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>; }; meta: object; errorShape: { ...; }; transformer: typeof SuperJSON; }>; ... 5 more ...; _meta: object; }>' is not assignable to type 'string'.ts(2322)
index.d.ts(1825, 5): The expected type comes from property 'email' which is declared here on type '(Without<UsersCreateInput, UsersUncheckedCreateInput> & UsersUncheckedCreateInput) | (Without<...> & UsersCreateInput)'
Why am I getting this? Using tRPC
Solution:
```tsx import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; export const postsCreateUser = createTRPCRouter({ checkUser: publicProcedure.input(z.string()).query(async ({ ctx, input }) => {...
Jump to solution
6 Replies
Neto
Neto2y ago
if you want to receive something from the query you need to add a .input() to the query
Solution
Neto
Neto2y ago
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";

export const postsCreateUser = createTRPCRouter({
checkUser: publicProcedure.input(z.string()).query(async ({ ctx, input }) => {
const user = await ctx.prisma.users.create({
data: {
email: input,
},
});
return user;
}),
});
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";

export const postsCreateUser = createTRPCRouter({
checkUser: publicProcedure.input(z.string()).query(async ({ ctx, input }) => {
const user = await ctx.prisma.users.create({
data: {
email: input,
},
});
return user;
}),
});
yourny🤫🧏🏼
Now it's fixed, but getting error while trying to use it
yourny🤫🧏🏼
const test = api.createUser.checkUser.useQuery({ email: `${user.user?.fullName}` });
const test = api.createUser.checkUser.useQuery({ email: `${user.user?.fullName}` });
Neto
Neto2y ago
remove the {email}
const test = api.createUser.checkUser.useQuery(user.user?.fullName);
const test = api.createUser.checkUser.useQuery(user.user?.fullName);
yourny🤫🧏🏼
Thank you!
Want results from more Discord servers?
Add your server