-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.ts
27 lines (23 loc) · 852 Bytes
/
context.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { SignedInAuthObject, SignedOutAuthObject } from '@clerk/clerk-sdk-node';
import { inferAsyncReturnType } from '@trpc/server';
import { CreateExpressContextOptions } from '@trpc/server/adapters/express';
import { Request } from 'express';
import prisma from '~/clients/prisma';
export type SignedInWithOrgAuthObject = SignedInAuthObject & {
orgId: string;
};
interface MaybeAuthedRequest extends Request {
auth: SignedInWithOrgAuthObject | SignedInAuthObject | SignedOutAuthObject | undefined;
}
/**
* Creates context for an incoming request
* @link https://trpc.io/docs/context
*/
// created for each request
export const createContext = async ({ req }: CreateExpressContextOptions) => {
return {
db: prisma,
auth: (req as MaybeAuthedRequest).auth,
};
};
export type Context = inferAsyncReturnType<typeof createContext>;