Serializing date with superjson

Think I'm going wrong somewhere implementing a server side request for the user and serlializing the data with superjson. Any ideas? export const getServerSideProps = async ({ req, res }: GetServerSidePropsContext) => { const session = await getServerSession(req, res, authOptions) const ssg = createProxySSGHelpers({ router: appRouter, ctx: await createContextInner({ session: null }), transformer: superjson, }) if (session?.user && !session.user.onboarded) { const user = await ssg.user.getById.fetch({ userId: session.user.id }) const teams = await prisma.team.findMany({ select: { id: true, name: true, image: true, }, }) return { props: { trpcState: ssg.dehydrate(), user: user, teams: teams, }, } } }
5 Replies
vibbin
vibbin2y ago
Error code I'm getting is for the verifiedemail object. Error: Error serializing .user.emailVerified returned from getServerSideProps in "/onboarding". Reason: object ("[object Date]") cannot be serialized as JSON. Please only return JSON serializable data types.
thejonyboybr
thejonyboybr2y ago
I'm having this same problem since trpc went to v10, let's open an issue maybe this is a bug? or maybe this is a problem on the configuration on the ct3app template for trpc but I don't see how
thejonyboybr
thejonyboybr2y ago
okay, I found out the solution, simply install https://github.com/blitz-js/babel-plugin-superjson-next
GitHub
GitHub - blitz-js/babel-plugin-superjson-next: Automatically transf...
Automatically transform your Next.js Pages to use SuperJSON - GitHub - blitz-js/babel-plugin-superjson-next: Automatically transform your Next.js Pages to use SuperJSON
thejonyboybr
thejonyboybr2y ago
also, there is a cleaner solution, without the babel plugin, see this discussion here: https://github.com/trpc/trpc/discussions/2925
GitHub
bug: Prefetching with SSG helpers still makes the query fetch on th...
Provide environment information System: OS: Linux 5.10 Ubuntu 20.04.5 LTS (Focal Fossa) Container: Yes Shell: 5.8 - /usr/bin/zsh Binaries: Node: 16.17.0 - /usr/bin/node npm: 8.15.0 - /usr/bin/npm n...
esponges
esponges2y ago
I'm on v.10.7.0 and I still see this issue (it says its been fixed already) and I'd love to avoid adding a new dependency
Want results from more Discord servers?
Add your server