meal_planner/server/trpc/context.ts
2024-12-15 01:18:09 +01:00

22 lines
580 B
TypeScript

import type { inferAsyncReturnType } from "@trpc/server";
/**
* Creates context for an incoming request
* @link https://trpc.io/docs/context
*/
export async function createContext(event: H3Event) {
const authorization = getRequestHeader(event, "authorization");
async function getUserFromHeader() {
if (authorization) {
console.log("authorization:", authorization);
return { isAdmin: true };
}
return null;
}
const user = await getUserFromHeader();
return {
user,
};
}
export type Context = inferAsyncReturnType<typeof createContext>;