hachoter
hachoter15mo ago

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
0 Replies
No replies yetBe the first to reply to this messageJoin