mirror of
https://github.com/rjNemo/meal_planner
synced 2026-06-06 02:26:49 +00:00
22 lines
580 B
TypeScript
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>;
|