17 lines
509 B
TypeScript
17 lines
509 B
TypeScript
import getServerConfig from '@/config/server';
|
|
import type { inferAsyncReturnType } from '@trpc/server';
|
|
import type { CreateNextContextOptions } from '@trpc/server/adapters/next';
|
|
import { getCookie } from 'cookies-next';
|
|
|
|
const { COOKIE_TOKEN_NAME } = getServerConfig();
|
|
|
|
export async function createContext({ req, res }: CreateNextContextOptions) {
|
|
const token = getCookie(COOKIE_TOKEN_NAME, { req, res });
|
|
|
|
return {
|
|
token,
|
|
};
|
|
}
|
|
|
|
export type Context = inferAsyncReturnType<typeof createContext>;
|