session does not exist in SSR using with createProxySSGHelpers

Hello, I'm following TRPC docs and I want to fetch user decks in getServerSideProps using createProxySSGHelpers, but I'm getting 'UNAUTHORIZED' error am I missing something? it should be returned from createContextInner right?
export async function getServerSideProps(context: GetServerSidePropsContext) {
const test = await createContextInner();

const ssg = createProxySSGHelpers({
router: appRouter,
ctx: await createContextInner(),
transformer: superjson,
});

await ssg.deckRouter.getAllUserDecks.fetch();

return {
props: {},
};
}
export async function getServerSideProps(context: GetServerSidePropsContext) {
const test = await createContextInner();

const ssg = createProxySSGHelpers({
router: appRouter,
ctx: await createContextInner(),
transformer: superjson,
});

await ssg.deckRouter.getAllUserDecks.fetch();

return {
props: {},
};
}
6 Replies
Neto
Neto2y ago
the procedure is called getAllUserDecks but createContextInner doesnt have an user
Bozic0909
Bozic0909OP2y ago
yes and its looks like this
getAllUserDecks: protectedProcedure.query(({ ctx }) => {
return ctx.prisma.deck.findMany({
where: {
userId: ctx.session.user.id,
},
});
}),
getAllUserDecks: protectedProcedure.query(({ ctx }) => {
return ctx.prisma.deck.findMany({
where: {
userId: ctx.session.user.id,
},
});
}),
getAllUserDecks takes userID from session, and session should exist in createContextInner?
Neto
Neto2y ago
yep get user session from next-auth before the const ssg pass it down on the inner context
Bozic0909
Bozic0909OP2y ago
ouhhh thank you, that worked one more question, is it normal to still se a loading for a half of second when prefetching data for query?
Neto
Neto2y ago
ssr so yea
Bozic0909
Bozic0909OP2y ago
thanks
Want results from more Discord servers?
Add your server