ElectricCodeGuy/SupabaseAuthWithSSR

Supabase Auth + AI Stack for Next.js 16 with SSR and React Server Components (RSC), Welcome to a production-ready template combining Supabase SSR authentication with AI capabilities: document chat (RAG), web search, and multiple LLM support. Features include secure file storage, vector search (pgvector), and persistent chat history.

SupabaseAuthWithSSR – Production‑grade AI chat starter for Next.js

What it is – A ready‑to‑run web app that combines Next.js 16, Supabase SSR authentication, and Claude (Anthropic) LLM to deliver a full‑featured AI chat experience. It ships with a single SQL file that creates the whole database schema (tables, RLS policies, triggers, storage policies, search functions, and model catalog). After cloning, installing dependencies, running the setup.sql script and adding a few API keys, you have a live chat product that includes:

Feature How it works
Secure auth Supabase SSR sign‑up / sign‑in / magic‑link flow, with server‑side session handling and row‑level security on every table.
Eight AI tools Document RAG (PDF OCR → embeddings → hybrid vector/keyword search), web search (Exa), artifact workspace (versioned markdown), long‑term memory, conversation search, interactive chart generation, PDF creation, and local text‑to‑image generation (Qwen‑Image‑2.1).
Cost‑aware usage Each generation step stores token counts and cache metadata as JSON on the message_parts row; dashboards aggregate per‑user and admin‑level KPIs, cache‑hit rates, and estimated spend.
Prompt caching A two‑tier Anthropic cache (static system prompt + moving breakpoint) reduces input token cost to ~10 % for multi‑step tool turns.
Versioned artifacts The “Artifacts” side‑panel streams AI‑written markdown live; every create/update is persisted as a version without extra tables.
PDF & chart rendering Uses @react-pdf/renderer for styled PDFs and client‑side chart libraries (Chart.js, ECharts, D3, etc.) for interactive visualizations.
Self‑hosted image generation Optional local server (Qwen‑Image‑2.1) exposes an OpenAI‑compatible /v1/images/generations endpoint, avoiding per‑image API fees.
Admin console Users flagged is_admin can view organization‑wide usage, top spenders, and manage user roles.

Tech stack

  • Framework: Next.js 16 (app router, server actions)
  • Auth & DB: Supabase (PostgreSQL, pgvector, RLS, storage buckets)
  • LLM: Anthropic Claude models via Vercel AI SDK (v7)
  • Embeddings: Voyage AI (voyage-4-large)
  • OCR: Mistral OCR model (mistral-ocr-latest)
  • Web search: Exa API
  • Image generation: Qwen‑Image‑2.1 served locally (FastAPI or vLLM‑Omni)
  • PDF: @react-pdf/renderer
  • Charts: client‑side libraries loaded from CDN (chart.js, echarts, d3, mermaid, three)
  • Styling: Tailwind CSS (implicit from Next.js starter)

Quick start (from the README)

git clone https://github.com/ElectricCodeGuy/SupabaseAuthWithSSR.git
cd SupabaseAuthWithSSR
npm install
cp .env.local.example .env.local   # fill in keys
npm run dev
  1. In the Supabase dashboard run database/setup.sql – the whole schema is idempotent.
  2. Create a private storage bucket named userfiles (RLS policies are already defined).
  3. Populate .env.local with the required keys (Supabase, Anthropic, Mistral, Voyage, Exa, optional image‑server URL).
  4. Sign up at http://localhost:3000/signup and confirm the email.
  5. (Optional) Grant admin rights via SQL: UPDATE public.users SET is_admin = true WHERE email = 'you@example.com';

Typical use cases

  • Legal or knowledge‑base assistants – upload PDFs, let the AI retrieve and cite passages (the repo powers a Danish legal‑AI platform).
  • Report generation – ask the assistant to analyse data, render charts, and export a polished PDF.
  • Creative image creation – generate logos or illustrations on‑premise without third‑party costs.
  • Multi‑tool workflows – a single user prompt can trigger web search, document lookup, charting, and PDF creation in one turn, with the full reasoning trace persisted.
  • Cost monitoring – per‑token accounting lets product teams track spend and optimize caching.

License

MIT – free for commercial or personal use.


All details above are taken directly from the repository’s README; no additional features have been inferred.

Related

  • Project
  • Project
  • Project
  • Project
  • Project