This workspace provides configured Supabase client instances and related utilities for interacting with the Supabase backend throughout the monorepo, particularly tailored for Server-Side Rendering (SSR) environments like Next.js.
To centralize the creation and configuration of Supabase clients for both client-side (browser) and server-side contexts. It also manages the generation of TypeScript types based on the Supabase database schema.
src/client.ts: Exports acreateSBBrowserClientfunction that uses@supabase/ssr'screateBrowserClientto create a Supabase client instance configured for use in the browser.src/server.ts: Exports acreateSBServerClientasync function that uses@supabase/ssr'screateServerClientandnext/headerscookies to create Supabase client instances configured for server-side environments (e.g., Next.js API routes, Server Components). It handles cookie retrieval and setting for authentication.src/lib.ts: Re-exports common types (likeUser,AuthError) from@supabase/supabase-jsand@supabase/ssr, and also re-exportscreateServerClientfor convenience.src/types.ts: Contains TypeScript definitions automatically generated from thepublicschema of the connected Supabase database. This file is generated by thetypegenscript (pnpm typegen) using the local development database.
Key exports (client, lib, server, types) are defined in package.json.
- @supabase/supabase-js: The official JavaScript client library for Supabase.
- @supabase/ssr: Helper library specifically designed for integrating Supabase authentication and client management within SSR frameworks (like Next.js).
- cookie: Utility library for parsing and serializing HTTP cookies, used internally by
@supabase/ssrserver-side clients. - Next.js (dependency): The presence of
next(specificallynext/headers) is required for the server-side cookie handling insrc/server.ts. - Supabase CLI: Used by the
typegenscript to generate types from the local database schema.
Depends On:
-
@op/core: To access shared configuration such as Supabase URL, anon key, and cookie domain settings used in client/server creation. -
@op/typescript-config(Dev): Used for TypeScript configuration during development.
Depended On By:
@op/hooks: Uses the browser client (createSBBrowserClientfrom./client.ts) provided by this package.@op/trpc: Uses the server client (createServerClientre-exported from./lib.ts) and database types (./types.ts), likely within the tRPC context creation.apps/api: Uses server-side client utilities (likely via@op/trpccontext).apps/app: Uses client-side (./client.ts) and server-side (./server.ts, often via Server Components or Route Handlers) client utilities.
- Type Generation: Run
pnpm typegento updatesrc/types.tsbased on the schema of your local Supabase instance (ensure the local Supabase stack is running viapnpm startinservices/db). This should typically be done after running database migrations in the@op/dbpackage. - Type Check: Run
pnpm typecheckto type-check the code.