File size: 3,313 Bytes
b387e01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# 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

1. Go to [https://supabase.com](https://supabase.com) → New project  
2. Open **Project Settings → API** and copy:
   - Project URL → `SUPABASE_URL`
   - `anon` `public` key → `SUPABASE_ANON_KEY`
   - `service_role` key → `SUPABASE_SERVICE_ROLE_KEY` (server only — never put in the browser)
3. 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:7860`
- `http://localhost:7860`
- your Hugging Face / production URL

## 4. Configure PlainRewrite

Copy `.env.example``.env` and fill keys:

```env

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:

```sql

update public.profiles

set role = 'admin'

where email = 'you@example.com';

```

Manage users/plans in the Supabase dashboard (no custom admin UI yet):

- `profiles` — change `plan_id` (`free` / `pro` / `plus`), set `status` to `disabled`
- `plans` — change limits / INR prices
- `usage_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 UI  
- `GET /v1/me` — account + remaining quota  
- `POST /v1/rewrite` — requires `Authorization: Bearer <access_token>` when auth is on  

## 7. Stripe later

1. Create Stripe products for Pro (₹199) / Plus (₹499)  
2. On `checkout.session.completed` webhook, set:

```sql

update public.profiles set plan_id = 'pro' where id = '<user_uuid>';

```

No schema change required beyond what you already have.