xdxd#5555 / hanya
xdxd#5555 / hanyaβ€’2y ago

Adding clerk auth object to createServerSideHelpers

So I followed clerk's docs for TRPC (https://clerk.com/docs/nextjs/trpc) and I added auth to the context object. This works great for most requests I've made, but I'm having trouble now that I'm trying to use getStaticProps and createServerSideHelpers. I slightly changed the AuthContext type so that auth can be undefined, which would make sense when the page is generated at build. But is there a way to get auth info in there, when the page gets regenerated later as a user visits? Or would I need to make any auth-related stuff part of the client code? Snippet:
export const getStaticProps: GetStaticProps = async (context) => {
const helpers = createServerSideHelpers({
router: appRouter,
ctx: { prisma, auth: undefined }, // would like to define auth if possible!
transformer: superjson,
});
...
export const getStaticProps: GetStaticProps = async (context) => {
const helpers = createServerSideHelpers({
router: appRouter,
ctx: { prisma, auth: undefined }, // would like to define auth if possible!
transformer: superjson,
});
...
TRPC | Clerk
Learn how to integrate Clerk into your Next.js with TRPC
1 Reply
π›ˆπž‚π—Ώπžˆπ’†π’ˆπ–π°π›ˆ 𝐜0πŸƒ3𝗿
You need to use getServerSideProps if you need to access authentication info, it's because of how Next.js works and not a trpc limitation