2023-03-09 08:14:29 +00:00
|
|
|
import * as trpcNext from "@trpc/server/adapters/next";
|
|
|
|
import { SALEOR_AUTHORIZATION_BEARER_HEADER, SALEOR_API_URL_HEADER } from "@saleor/app-sdk/const";
|
|
|
|
import { inferAsyncReturnType } from "@trpc/server";
|
2023-06-20 09:38:32 +00:00
|
|
|
import { getBaseUrl } from "../../lib/get-base-url";
|
2023-03-09 08:14:29 +00:00
|
|
|
|
|
|
|
export const createTrpcContext = async ({ res, req }: trpcNext.CreateNextContextOptions) => {
|
2023-06-20 09:38:32 +00:00
|
|
|
const baseUrl = getBaseUrl(req.headers);
|
|
|
|
|
2023-03-09 08:14:29 +00:00
|
|
|
return {
|
|
|
|
token: req.headers[SALEOR_AUTHORIZATION_BEARER_HEADER] as string | undefined,
|
|
|
|
saleorApiUrl: req.headers[SALEOR_API_URL_HEADER] as string | undefined,
|
|
|
|
appId: undefined as undefined | string,
|
|
|
|
ssr: undefined as undefined | boolean,
|
2023-06-20 09:38:32 +00:00
|
|
|
baseUrl,
|
2023-03-09 08:14:29 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export type TrpcContext = inferAsyncReturnType<typeof createTrpcContext>;
|