// api.ts file in lib folder
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from '../../../backend/src/router';
export const api = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: 'http://localhost:5173/api',
// You can pass any HTTP headers you wish here
async headers() {
return {
authorization: (localStorage.getItem('token')
? localStorage.getItem('token')
: '') as string
};
}
})
]
});
// api.ts file in lib folder
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from '../../../backend/src/router';
export const api = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: 'http://localhost:5173/api',
// You can pass any HTTP headers you wish here
async headers() {
return {
authorization: (localStorage.getItem('token')
? localStorage.getItem('token')
: '') as string
};
}
})
]
});