juicoJ
tRPC3y ago
17 replies
juico

trpc mutation call stuck

I have an issue with a simple mutation procedure:

getPublicUser: publicProcedure .input(z.object({ walletAddress: z.string() })) .mutation(async ({ ctx, input }) => { console.log('ctx.prisma: ', ctx.prisma) try { const user = await ctx.prisma.users.findUnique({ where: { walletAddress: input.walletAddress }, select: { walletAddress: true, id: true, } }) return user } catch (e: any) { console.log('E: ', e) } })

It shows in my console that it calls the mutation successfully, but it keeps on being stuck. It does not log the first like in the code even.

My trpc.ts setup:

const t = initTRPC.context<typeof createTRPCContext>().create({ transformer: superjson, errorFormatter({ shape, error }) { return { ...shape, data: { ...shape.data, zodError: error.cause instanceof ZodError ? error.cause.flatten() : null, }, }; }, }); export const createTRPCContext = async (_opts: CreateNextContextOptions) => { const { req, res } = _opts; async function getUserFromHeader() { console.log('req.headers.authorization: ', req.headers.authorization) if (req.headers.authorization && req.headers.authorization.split(' ')[1]) { try { const token = localStorage.getItem('crypties:auth') if (!token) return null; const parsedToken = JSON.parse(token); if (new Date(parsedToken.validUntil) < new Date()) return null console.log('token: ', token) const user = await prisma.users.findFirst({ where: { walletAddress: parsedToken.userWalletAddress }, }); return user; } catch (error) { return null; } } return null; } return { req, res, user: await getUserFromHeader(), prisma }; }; export const publicProcedure = t.procedure;
Was this page helpful?