feat: switch TRPC router to edge

This commit is contained in:
Henry
2024-04-27 17:02:02 +01:00
parent d15870118d
commit 0035aa6500
6 changed files with 63 additions and 31 deletions

View File

@@ -7,11 +7,11 @@
* need to use are documented accordingly near the end.
*/
import { initTRPC, TRPCError } from "@trpc/server";
import { type CreateNextContextOptions } from "@trpc/server/adapters/next";
import { type FetchCreateContextFnOptions } from "@trpc/server/adapters/fetch";
import superjson from "superjson";
import { ZodError } from "zod";
import createClient from "~/utils/supabase/api";
import { createTRPCClient } from "~/utils/supabase/api";
import { type Database } from "~/types/database.types";
import { type SupabaseClient } from "@supabase/supabase-js";
@@ -56,8 +56,11 @@ export const createInnerTRPCContext = (opts: CreateContextOptions) => {
*
* @see https://trpc.io/docs/context
*/
export const createTRPCContext = async (_opts: CreateNextContextOptions) => {
const db = createClient(_opts.req, _opts.res);
export const createTRPCContext = async ({
req,
resHeaders,
}: FetchCreateContextFnOptions) => {
const db = createTRPCClient(req, resHeaders);
const {
data: { user },