TanStackT
TanStack4w ago
9 replies
dual-salmon

Type safe Supabase client building off of the basic example

I used the example app for getting started with Supabase and Start and everything is working fine for the most part except when I want to pass the
Database
type to the create client code. I get errors on all of my queries despite them being correct and working as to be expected.

Can anyone tell me how to type the following function correctly please

import { getCookies, setCookie } from "@tanstack/react-start/server";
import { createServerClient } from "@supabase/ssr";
import { Database } from "./types";

export function getSupabaseServerClient() {
  return createServerClient(
    process.env.SUPABASE_URL!,
    process.env.SUPABASE_ANON_KEY!,
    {
      cookies: {
        getAll() {
          return Object.entries(getCookies()).map(([name, value]) => ({
            name,
            value,
          }));
        },
        setAll(cookies: Record<string, string>[]) {
          cookies.forEach((cookie) => {
            setCookie(cookie.name, cookie.value);
          });
        },
      },
    }
  );
}


when I was passing the types it was like so createServerClient<Database> so perhaps this is the bit that is incorrect.

Any help appreciated!
Was this page helpful?