25 lines
615 B
TypeScript
25 lines
615 B
TypeScript
import { getUser } from '@/api/user/query';
|
|
import { getCurrentScope } from '@sentry/node';
|
|
import type { inferAsyncReturnType } from '@trpc/server';
|
|
import type { CreateNextContextOptions } from '@trpc/server/adapters/next';
|
|
|
|
export async function createContext({ req }: CreateNextContextOptions) {
|
|
const { cookie = '', authorization } = req.headers;
|
|
|
|
const user = await getUser({
|
|
headers: {
|
|
cookie,
|
|
},
|
|
});
|
|
|
|
const scope = getCurrentScope();
|
|
scope.setUser(user);
|
|
|
|
return {
|
|
headers: { authorization },
|
|
user,
|
|
};
|
|
}
|
|
|
|
export type Context = inferAsyncReturnType<typeof createContext>;
|