GitHub

Credit System

Mail Assist uses a credit-based system to manage user access to email sending features. Each action deducts a specific number of credits, ensuring fair usage and scalability.

Default Credits

Every new user is initialized with 300 credits in the `profiles` table.

profiles table snippet
id UUID PRIMARY KEY REFERENCES auth.users(id),
username TEXT,
credits INTEGER DEFAULT 300,
created_at TIMESTAMP DEFAULT now()

Credit Deduction Logic

Credits are deducted automatically when a user sends emails via different methods:

  • Custom Email: 5 credits
  • Templated Email: 10 credits
  • Batch Email: 10 credits per recipient
Note
If the user does not have enough credits, the request will be denied.

Deduction Example

deductCredits.ts
// Custom email (5 credits)
const { data, error } = await supabase
  .from("profiles")
  .update({ credits: user.credits - 5 })
  .eq("id", user.id)
  .select();
checkCreditBeforeSend.ts
if (user.credits < requiredCredits) {
  throw new Error("Insufficient credits");
}

Refill Credits

Admins (or later: paid plans) can refill user credits manually or programmatically. Here's an example:

Refill Credits
UPDATE profiles
SET credits = credits + 100
WHERE id = 'uuid-of-user';
Coming Soon
A Stripe-powered credit purchase system is planned for future versions.

Monitor Credits

Credits can be shown in the user dashboard using Supabase queries:

getUserProfile.ts
const { data: profile } = await supabase
  .from("profiles")
  .select("username, credits")
  .eq("id", user.id)
  .single();