heyitsiveenH
tRPC10mo ago
22 replies
heyitsiveen

Error: Switched to client rendering because the server rendering errored: UNAUTHORIZED

What could be the possible reason for this error?

This is how my NextJS structure looks when using tRPC.

- /app/settings/page.tsx
export const dynamic = 'force-dynamic'

export default function Settings() {
  prefetch(trpc.categories.getMany.queryOptions())
  return (
    <HydrateClient>
      <CategoriesView />
    </HydrateClient
  )
}


- /components/settings/view/categories-view.tesx
'use client'
export const CategoriesView = () => {
  return <CategoriesSection />
}


- /components/settings/section/categories-section.tsx
export const CategoriesSection = () => {
  return (
    <Suspense fallback={<p>Loading...</p>}
      <ErrorBoundary fallback={<p>Error</p>}
        <CategoriesSectionSuspense />
      </ErrorBoundary>
    </Suspense>
  )
}

const CategoriesSectionSuspense = () => {
  const trpc = useTRPC()
  const { data } = useSuspenseQuery(trpc.categories.getMany.queryOptions())

  return <CategoriesDataTable data={data} />
}
received_1046152650732400.png
Was this page helpful?