Skip to content

Accounts and hosted AI credits on Clerk and Neon; remove Supabase - #34

Merged
I-794 merged 2 commits into
mainfrom
claude/practical-archimedes-s2nxsa
Nov 14, 2026
Merged

I-794 merged 2 commits into
mainfrom
claude/practical-archimedes-s2nxsa

Conversation

@I-794

@I-794 I-794 commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Groundwork for Glint Pro. Not a versioned release: no version bump, no changelog entry. The studio stays free.

Accounts and hosted AI credits

  • api/_account.js: metered(kind, handler) wraps the six hosted AI routes. It verifies the caller's Clerk session token (@clerk/backend), spends credits before the model call (1 for text / vision / enhance / agent, 5 for an image) and refunds them when the route answers with an error. Answers 401 { code: 'sign_in' } or 402 { code: 'no_credits' }; a Clerk or database failure answers 503.
  • Plans and monthly credit counts live in Neon Postgres (@neondatabase/serverless). The schema is api/_account-schema.js (two tables and one atomic function) and the server installs it on first use.
  • api/account.js is one function for every account route (?op=me today). That makes 11 of 12 serverless functions.
  • Defaults: 20 free and 500 Pro credits a month (AI_FREE_CREDITS, AI_PRO_CREDITS).
  • Metering is off until the deployment has a Clerk key and a database URL. Without them the hosted AI routes behave as before.

Editor

  • src/features/auth.js is rewritten for Clerk. Clerk's browser bundles load from the Clerk instance at runtime, so no Clerk package is in the build; without a publishable key no sign-in UI shows and nothing loads.
  • src/features/account.js hostedFetch() is now the only way to call a hosted AI route. It adds the token, explains a sign-in or out-of-credits answer, and falls back to the person's own API key. A header chip shows credits left.
  • The build reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY (the name Clerk's Vercel Marketplace install adds) or VITE_CLERK_PUBLISHABLE_KEY.

Removed

  • Supabase and everything that depended on it: cloud project and template sync, the community gallery, live collaboration, the unwired campaign mirror, and the "Set up cloud" and sign-in dialogs. None of these were connected on the live site. Projects stay in the browser.

Copy and docs

  • Pricing, privacy, terms, FAQ, AI, guide and gallery pages no longer mention syncing or a community gallery; privacy describes Clerk and credit counting.
  • DEPLOY.md, MIGRATION.md, docs/BACKEND.md, README.md and CLAUDE.md updated. docs/BACKEND.md also corrects CRON_SECRET (it has to be added by hand).

Checks

  • npm run check passes (lint, knip, tests, build). testHostedAiIsMetered signs throwaway Clerk-shaped tokens and covers sign-in, limits, refunds, Pro and failure cases.
  • The schema and credit function were run against a local Postgres 16.
  • The editor was driven in a headless browser against a stand-in Clerk: signed out, signed in, sign out, credits chip, Clerk unreachable, and no key.
  • A build with a fake secret confirmed the publishable key reaches the bundle and CLERK_SECRET_KEY does not.
  • Not tested: the real Clerk and Neon services, which need the Marketplace installs.

After merging

  • Add Clerk and Neon from the Vercel Marketplace and redeploy to turn sign-in and metering on.

Generated by Claude Code

Hosted AI routes can now count credits per signed-in Supabase account: 1 per text, vision, enhance or agent call, 5 per image, 20 free a month by default. supabase/glint-pro.sql adds the subscriptions and ai_usage tables and one atomic credit function; api/_account.js checks the login token, spends before the model call and refunds failed calls; api/account.js serves the account's usage. The editor sends the token through one helper, explains a sign-in or out-of-credits answer, falls back to the person's own key, and shows credits left in the header. Metering stays off until SUPABASE_SERVICE_ROLE_KEY is set on the deployment.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016tciSRcwDsHcLgxbSDvQgC
Supabase is removed. Sign-in is now Clerk, loaded from the Clerk instance at runtime so nothing is added to the build, and plans and hosted AI credit counts live in Neon Postgres. The server verifies Clerk session tokens and installs its own schema (two tables and one function) on first use, so there is no SQL to run by hand. Cloud project and template sync, the community gallery and live collaboration, which depended on Supabase and were not connected on the live site, are removed along with the Supabase setup dialogs. Site copy and docs updated to match. Metering stays off until a Clerk key and a database URL are present.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016tciSRcwDsHcLgxbSDvQgC
@vercel

vercel Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
glint Ready Ready Preview Nov 14, 2026 4:37am UTC

@I-794
I-794 merged commit 878e6ab into main Nov 14, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — fd1dcd41 Deployed Nov 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants