Supabase setup (Auth + plans + quotas)
PlainRewrite uses Supabase for Google + email login, Postgres profiles/plans/usage, and FastAPI JWT + quota checks. Stripe can be added later by flipping profiles.plan_id.
1. Create a free Supabase project
- Go to https://supabase.com → New project
- Open Project Settings → API and copy:
- Project URL →
SUPABASE_URL anonpublickey →SUPABASE_ANON_KEYservice_rolekey →SUPABASE_SERVICE_ROLE_KEY(server only — never put in the browser)
- Project URL →
- Optional: JWT Secret →
SUPABASE_JWT_SECRET
2. Run the schema
In Supabase → SQL Editor, paste and run:
supabase/schema.sql
This creates plans, profiles, usage_daily, and a trigger that auto-creates a Free profile on signup.
Default plans (INR):
| Plan | Daily rewrites | Max words / rewrite | Daily word cap | Price |
|---|---|---|---|---|
| Free | 5 | 400 | 1,500 | ₹0 |
| Pro | 50 | 2,000 | 15,000 | ₹199 |
| Plus | 200 | 5,000 | 50,000 | ₹499 |
Edit limits anytime in Table Editor → plans.
3. Enable auth providers
Authentication → Providers
- Email — enable (optional: disable “Confirm email” while testing)
- Google — enable; add Client ID/Secret from Google Cloud Console
Authorized redirect URI (from Supabase Google provider screen), typically:https://YOUR_PROJECT.supabase.co/auth/v1/callback
Authentication → URL Configuration
Add your app URLs to Redirect URLs, e.g.:
http://127.0.0.1:7860http://localhost:7860- your Hugging Face / production URL
4. Configure PlainRewrite
Copy .env.example → .env and fill keys:
SUPABASE_URL=https://xxxx.supabase.co
SUPABASE_ANON_KEY=eyJ...
SUPABASE_SERVICE_ROLE_KEY=eyJ...
SUPABASE_JWT_SECRET=your-jwt-secret
On Hugging Face Spaces / Docker, set the same as secrets / env vars.
- If these are empty, the app stays in open local mode (no login).
- If all three URL + anon + service role are set, login is required to rewrite.
5. Promote an admin
After you sign up once:
update public.profiles
set role = 'admin'
where email = 'you@example.com';
Manage users/plans in the Supabase dashboard (no custom admin UI yet):
profiles— changeplan_id(free/pro/plus), setstatustodisabledplans— change limits / INR pricesusage_daily— inspect quotas
6. How it works
Browser (Supabase Auth) → JWT
↓
FastAPI verifies JWT
↓
Load profile + plan + today's usage (service role)
↓
Enforce limits → rewrite → increment usage
API:
GET /v1/auth/config— public anon config for the UIGET /v1/me— account + remaining quotaPOST /v1/rewrite— requiresAuthorization: Bearer <access_token>when auth is on
7. Stripe later
- Create Stripe products for Pro (₹199) / Plus (₹499)
- On
checkout.session.completedwebhook, set:
update public.profiles set plan_id = 'pro' where id = '<user_uuid>';
No schema change required beyond what you already have.