mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-11 14:41:46 -05:00
30 lines
603 B
TypeScript
30 lines
603 B
TypeScript
import * as trpc from "@trpc/server";
|
|
import * as trpcExpress from "@trpc/server/adapters/express/dist/trpc-server-adapters-express.cjs";
|
|
|
|
export const createContext = ({
|
|
req,
|
|
res,
|
|
}: trpcExpress.CreateExpressContextOptions) => {
|
|
const getUser = () => {
|
|
if (!req.user) {
|
|
return;
|
|
}
|
|
return req.user as {
|
|
id: number;
|
|
discordId: string;
|
|
discordAvatar?: string;
|
|
};
|
|
};
|
|
|
|
return {
|
|
req,
|
|
res,
|
|
user: getUser(),
|
|
};
|
|
};
|
|
type Context = trpc.inferAsyncReturnType<typeof createContext>;
|
|
|
|
export function createRouter() {
|
|
return trpc.router<Context>();
|
|
}
|