Skip to content
Discussion options

You must be logged in to vote

@ahmedivy if i understand correctly, during prerendering (static generation), Next.js generates HTML at build time or during the first request. At that point, there's no actual HTTP request, so there are no headers to access.

When your component tries to make an API call → the ORPC client tries to call headers throws during prerendering because there's no request context.

To fix this, you can use connection() like:

import { api } from "@/lib/api";
import { connection } from "next/server";

export async function UserAvatar() {
  await connection();
  
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const user = await (api as any).user.currentUser();
  return <pre>{JSON.s…

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@ahmedivy
Comment options

@ahmedivy
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@icyJoseph
Comment options

Comment options

You must be logged in to vote
2 replies
@ahmedivy
Comment options

@dieguezz
Comment options

Answer selected by ahmedivy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants