tRPCttRPC
Powered by
hachoterH
tRPC•3y ago•
1 reply
hachoter

Server side headers are not applied

Hi guys I have the following trpc client initialized
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from '../../../api/src/trpc';
import { get } from 'js-cookie';

export const client = createTRPCProxyClient<AppRouter>({
    links: [
        httpBatchLink({
            url: 'http://localhost:8000/trpc',
            headers: () => {
                return {
                    authorization: get('authToken')
                };
            }
        })
    ]
});
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from '../../../api/src/trpc';
import { get } from 'js-cookie';

export const client = createTRPCProxyClient<AppRouter>({
    links: [
        httpBatchLink({
            url: 'http://localhost:8000/trpc',
            headers: () => {
                return {
                    authorization: get('authToken')
                };
            }
        })
    ]
});

The problem is that the header doesn't get applied when it's being called on the server, I use a route to authenticate users and I wanna be able to call that from the server as well but I can't figure out how to pass the token, if it would be a regular fetch request I would simply add the cookie but in the callback function I don't have access to the request context, additionally I didn't find a way to add the headers on an individual query only on the client level
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Forward client headers with createTRPCProxyClient & Server-Side Helpers
NeoBeanNNeoBean / ❓-help
3y ago
server side prefetch + optional client side refetch
PeformPPeform / ❓-help
12mo ago
handling errors server side
agiAagi / ❓-help
3y ago