5 Replies
But when I try to call any protectedprocedure when logged-in, it gives the unauthorized error.
Is it cause the headers is client side and the trpc can't use it?
The headers come from your trpc route so no not really. How are you setting the context in your route?
the context code is here already i just call protectedprocedure
getMe: protectedProcedure
.query(async ({ ctx }) => {
try {
const response = await axios.get(
${API_BASE_URL}/api/example
,
{
headers: { "X-API-Key": ctx.dbUser.apiKey },
}
);
const user = response.data as UserInDB;
return {
...user,
discordId: user.discord_id?.toString?.() ?? user.discord_id,
};
} catch (error) {
handleApiError(error, "getMe");
}
}),Yes, but how do you actually call the
createTRPCContext
function in your route with the headers?