Skip to content

Latest commit

 

History

History
44 lines (28 loc) · 3.27 KB

File metadata and controls

44 lines (28 loc) · 3.27 KB

@op/supabase Workspace

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.

Purpose

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.

Structure

  • src/client.ts: Exports a createSBBrowserClient function that uses @supabase/ssr's createBrowserClient to create a Supabase client instance configured for use in the browser.
  • src/server.ts: Exports a createSBServerClient async function that uses @supabase/ssr's createServerClient and next/headers cookies 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 (like User, AuthError) from @supabase/supabase-js and @supabase/ssr, and also re-exports createServerClient for convenience.
  • src/types.ts: Contains TypeScript definitions automatically generated from the public schema of the connected Supabase database. This file is generated by the typegen script (pnpm typegen) using the local development database.

Key exports (client, lib, server, types) are defined in package.json.

Key Technologies

  • @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/ssr server-side clients.
  • Next.js (dependency): The presence of next (specifically next/headers) is required for the server-side cookie handling in src/server.ts.
  • Supabase CLI: Used by the typegen script to generate types from the local database schema.

Relationship to Other Workspaces

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 (createSBBrowserClient from ./client.ts) provided by this package.
  • @op/trpc: Uses the server client (createServerClient re-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/trpc context).
  • apps/app: Uses client-side (./client.ts) and server-side (./server.ts, often via Server Components or Route Handlers) client utilities.

Development

  • Type Generation: Run pnpm typegen to update src/types.ts based on the schema of your local Supabase instance (ensure the local Supabase stack is running via pnpm start in services/db). This should typically be done after running database migrations in the @op/db package.
  • Type Check: Run pnpm typecheck to type-check the code.