Repository navigation
Accounts and hosted AI credits on Clerk and Neon; remove Supabase - #34
Merged
Merged
Conversation
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
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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. Answers401 { code: 'sign_in' }or402 { code: 'no_credits' }; a Clerk or database failure answers 503.@neondatabase/serverless). The schema isapi/_account-schema.js(two tables and one atomic function) and the server installs it on first use.api/account.jsis one function for every account route (?op=metoday). That makes 11 of 12 serverless functions.AI_FREE_CREDITS,AI_PRO_CREDITS).Editor
src/features/auth.jsis 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.jshostedFetch()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.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY(the name Clerk's Vercel Marketplace install adds) orVITE_CLERK_PUBLISHABLE_KEY.Removed
Copy and docs
DEPLOY.md,MIGRATION.md,docs/BACKEND.md,README.mdandCLAUDE.mdupdated.docs/BACKEND.mdalso correctsCRON_SECRET(it has to be added by hand).Checks
npm run checkpasses (lint, knip, tests, build).testHostedAiIsMeteredsigns throwaway Clerk-shaped tokens and covers sign-in, limits, refunds, Pro and failure cases.CLERK_SECRET_KEYdoes not.After merging
Generated by Claude Code