"trpc failed on posts.getAll" - unsure what is broken and how to debug it?
I've gone through almost all of Theo's Chirp tutorial. I originally had the same middleware issue as other folks and used the matcher config code that was posted to solve that problem. I've been continuously testing my build throughout the tutorial. It was working perfectly when I finished the "profile feed" part - I committed and deployed to Vercel, and then it just stopped working and I get the "trpc failed on posts.getAll - Author not found" error. I even reverted my previous commits and the error keeps appearing. I am unsure how to solve this problem...
3 Replies
can you share the code?
Here's my postsRouter:
export const postsRouter = createTRPCRouter({
getAll: publicProcedure.query(async ({ ctx }) => {
const posts = await ctx.prisma.post.findMany({
take: 100,
orderBy: [{ createdAt: "desc" }],
});
const users = (
await clerkClient.users.getUserList({
userId: posts.map((post) => post.authorid),
limit: 100,
})
).map(filterUserForClient);
console.log(users);
return posts.map((post) => {
const author = users.find((user) => user.id === post.authorid);
if (!author || !author.username)
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Author not found",
});
return {
post,
author: {
...author,
username: author.username,
},
};
});
}),
According to the code, it's either the author or author.username is undefined, console.log(author) to find which one
Also check Theo implementation
https://github.com/t3dotgg/chirp/blob/main/src/server/api/routers/posts.ts
GitHub
chirp/posts.ts at main · t3dotgg/chirp
Contribute to t3dotgg/chirp development by creating an account on GitHub.