AuthSession in T3 boiler plate not working when fetching data in SSG with tRPC
So when fetching data in getStaticProps, the docs instruct to use the SSG headers https://trpc.io/docs/ssg. Now doing this causes the file in
server/common/get-server-auth-session
to throw errors because the context
will be undefined. What's the way to go around this8 Replies
As far as I know it's fundamentally not possible
SSG pages are generated at build time
how would there be a session?
That's what kept me wondering, but the error occurs once I fetch data in getStaticProps
Here is the code I use
im not on my computer now but i think you need to use the createContextInner function
that's the one that's not dependent on req/res existing
aight let me look on it
Yeah I have checked that and its included on the t3 boiler plate. But the error is occuring on this line
return await unstable_getServerSession(ctx.req, ctx.res, authOptions);
which comes from the file in server/common/get-server-auth-session
.
What am i missingif you're still doing this
ctx: await createContext(),
the createContext function tries to get your session
and there is no session
because there is no req and res
instead do ctx: await createContextInner({ session: null }),
Ooh shoot
I guess that will fix the error