Skip to content

Auth Headers + Next 15 + Tanstack Query + Hydration #330

Answered by timvandam
MaKTaiL asked this question in Q&A
Discussion options

You must be logged in to vote

You can pass headers to the RPCLink. However currently you are just creating one shared RPCLink and client for all requests (https://github.com/MaKTaiL/orpc-test-next/blob/main/src/server/orcp/client.ts#L13-L17).

Instead you should do that in your root component: https://github.com/MaKTaiL/orpc-test-next/blob/main/src/app/providers.tsx#L40-L50.

So in there add:

const [link] = useState(() => new RPCLink({ url: getBaseUrl() + "/rpc", headers: () => (typeof window === 'undefined' ? Object.fromEntries(headers().entries()) : ({}) }));
const [client] = useState<RouterClient<typeof router>>(() => createORPCClient(link));
const [orpc] = useState(() => createORPCReactQueryUtils(client));

Note that…

Replies: 5 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

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

@MaKTaiL
Comment options

Answer selected by unnoq
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants