7 min read11 views

Multi-Tenant Inventory Manager with Nuxt 3 and Supabase

A shop-billing SaaS on Nuxt 3 and Supabase: stock, invoices, UPI links, AI bill scan, and per-shop storefronts — with RLS so shop_id is never trusted from the client.

nuxtsupabasemulti-tenancyinventorysaasvuepiniavuetifyai
Multi-Tenant Inventory Manager with Nuxt 3 and Supabase

Quick Answer

A multi-tenant inventory manager is a shop OS where each store’s products, sales, and payments stay isolated by shop_id. I built mine with Nuxt 3, Pinia, Vuetify, and Supabase (Postgres + Auth + RLS), plus Nitro APIs for AI bill scan, payment emails, and a shop chatbot. Use this stack when a small shop needs billing, stock, quotations, and a public storefront without a separate mobile app.

Quick Facts

ItemDetails
TopicMulti-tenant inventory manager (Nuxt 3 + Supabase)
CategoryNuxt / Vue / SaaS / Supabase

What Is a Multi-Tenant Inventory Manager?

It’s not a single Excel sheet with a login page. Each shop gets its own catalog, invoices, suppliers, and (in my app) a public page under a slug or custom domain. The tenancy boundary is profiles.shop_id, enforced by Supabase RLS and again on every Nitro route via requireUser / requireAdmin.

I started this for a telecom-style shop that needed serial/IMEI tracking and UPI payment links. It grew into a small SaaS surface: marketing landing, shop-owner panel, per-shop storefront, and a platform admin for suspending shops and gating AI usage.

Why It Matters

  • Stock that matches the bill — purchase and sale line items update stock through Postgres triggers, so you don’t hand-edit quantities after every invoice.
  • Money trails that survive partial pay — cash, UPI, QR, pending, partial, rejected, and write-offs live on the sale plus a payments table.
  • AI that saves typing — photograph a purchase bill; vision models return line items matched to your catalog. A Hinglish shop chat answers “kitna pending?” from live data without mutating stock.
  • One deploy, many shops — same Nuxt app on Vercel; host/slug decides marketing vs panel vs storefront.

How It Works

Four layers move every request.

Secure multi-tenant flow: browser and Nuxt app through RLS shield to isolated shops and databases
Client uses the anon key under RLS; server routes resolve shop_id from the JWT profile, never from the request body.
  1. Auth session — Supabase PKCE in the browser; middleware sends you to login, onboarding (no shop yet), dashboard, or platform if you’re super_admin.
  2. Tenant scope — client Pinia stores filter by userStore.shopId; RLS uses get_my_shop_id(). Logout clears stores so the next account doesn’t see leftover rows.
  3. Domain logic — products (SKU unique per shop), purchases, sales with INV-YYYYMM-000N, quotations → convert to sale, services, suppliers, serials.
  4. Side systems — ImageKit signed uploads, Resend payment mail with UPI deep-link, AI bill parse with provider fallback, monthly AI quota per shop.

Step-by-Step Guide

This is the path I use when spinning up the same pattern — not every env var, just the spine.

Step 1: Lock the tenant model in Postgres

Create shops and profiles (profile FK to auth.users, shop_id nullable until onboarding). Add get_my_shop_id() as SECURITY DEFINER and turn RLS on every shop-owned table. Done looks like: two test users in two shops cannot select each other’s products even with the anon key.

Step 2: Wire Nuxt auth and server guards

Client plugin builds $supabase with the publishable key. Route middleware: no session → /login; session without shop → /onboarding; suspended shop → lock page. For /api/**, call requireAdmin(event), read ctx.shopId, and never accept shop_id from JSON. Done: forging another shop’s id in the body does nothing.

Step 3: Ship stock + invoice triggers, then the sharp edges

Add purchase/sale item triggers to bump stock. Generate invoice numbers in SQL. Then build the flows shops actually use: payment link tokens (24h), print/PDF, Excel product import, barcode scan, AI bill OCR behind a per-shop AI flag. Done: create a purchase from a scanned bill, create a UPI sale, open the verify link, and confirm stock and payment status both moved.

Phone scanning a purchase invoice beside a laptop inventory dashboard and connected shops
AI bill OCR: photo of a purchase bill becomes matched catalog lines before stock is applied.

Real-World Example

Stack: Nuxt 3 + Vuetify admin + Supabase + Nitro on Vercel. Goal: shop owner emails a UPI collect link for an unpaid invoice.

Bug: early versions were tempted to POST amount + customer email from the client. That’s spoofable — change the total in DevTools and the email lies.

Fix: client sends only paymentToken. POST /api/send-payment-email loads amount, invoice, shop branding, and expiry from the database with the authenticated user’s shop. Resend sends a UPI deep-link plus /payment/verify. Same rule as tenancy: trust the row, not the form.

Pros & Cons

Advantages

  • RLS + server shopId double fence — client bugs don’t become cross-shop leaks as easily.
  • One codebase covers panel, storefront, and platform admin.
  • AI bill scan and shop chat cut daily typing for owners who live on phone photos and Hinglish questions.
  • Triggers keep stock honest for the happy path of insert purchase/sale items.

Disadvantages

  • Sale edit/delete has no stock trigger — you must adjust products.stock in app code or quantities drift.
  • Invoice numbering via COUNT(*) + 1 is fine for a small shop, not for high-concurrency factories.
  • Vision API quotas fail often; you need OpenRouter → Groq → Gemini fallbacks and a monthly AI gate.
  • True host-split SaaS (www vs app. vs slug.) needs careful Vercel DNS and tenant resolve — easy to accidentally show shop #1 on an unknown host.

Best Practices

  • Keep the service-role key in server runtimeConfig only — never NUXT_PUBLIC_*.
  • Resolve tenant from JWT → profiles, then query; ignore client-sent shop_id.
  • On logout, clear every Pinia data store so the next login can’t flash the previous shop’s rows.
  • Gate AI per shop server-side (shop_admin_data + usage table), not with a checkbox the browser can flip.
  • Put new schema only in timestamped supabase/migrations/; treat root SQL dumps as reference, not the source of truth.
  • For payment and email routes, accept tokens/ids and re-read money fields from the DB.

Common Mistakes

  • Trusting shop_id in the request body — happens when the API mirrors a form. Fix: requireAdmin + ctx.shopId on every mutation.
  • Editing a sale without restoring stock — delete has no trigger. Fix: reverse quantities in the store/API before rewriting line items.
  • Exposing the service role to the SPA — “just for admin screens.” Fix: admin UI still uses the user JWT; only Nitro uses service role for platform-wide reads.
  • One Gemini key with no fallback — free tier 429s kill bill scan mid-day. Fix: provider order + status chip so the UI shows which path is live.
  • Unknown host falls back to the first shop — looks fine in demos, wrong in production. Fix: return unknown / 404; never default to shop row 1.

Frequently Asked Questions

What is a multi-tenant inventory manager?

It’s inventory and billing software where many shops share one app and database, but each shop only sees its own rows. Isolation usually comes from a tenant key (shop_id) plus database policies and server checks.

How do I get started with Nuxt 3 and Supabase for this?

Stand up Supabase Auth, shops/profiles, and RLS first. Then add a Nuxt client with the anon key and one Nitro route that calls requireUser and selects products for ctx.shopId. Prove isolation with two users before you build the invoice UI.

Nuxt + Supabase vs Laravel API + SPA?

Pick Nuxt + Supabase when you want one TypeScript codebase, RLS close to the data, and fast SaaS iteration on Vercel. Pick Laravel (or any dedicated API) when you need heavy domain jobs, complex queues, or a team already standardized on PHP backends — I even sketched a Laravel conversion epic for later.

Is building your own inventory SaaS worth it?

Yes if you’re solving a real shop workflow (serials, UPI links, Hindi/Hinglish ops) that off-the-shelf tools fight. No if you only need a generic SKU list — use an existing POS and save the months of RLS, payments, and edge cases.

Summary

A multi-tenant inventory manager on Nuxt 3 and Supabase is a shop-scoped billing system: RLS and Nitro guards own tenancy, triggers own stock for inserts, and server-side tokens own payment emails. AI bill scan and shop chat are accelerators, not the security model.

If you’re deep in Nuxt request flow next, see Nuxt lifecycle explained on this site — then come back and harden your shop_id path before you ship AI features.

Key Takeaways

  • Tenant identity belongs in the JWT profile and RLS, never in a client-supplied shop_id.
  • Stock triggers cover inserts; sale edits still need explicit stock math.
  • Payment and email APIs should accept a token and re-read amounts from the database.
  • AI bill OCR needs provider fallbacks and a per-shop quota, or production dies on 429s.
  • Marketing, shop panel, storefront, and platform admin can share one Nuxt deploy if host/slug resolution is strict.

Keep learning — next reads from the same topics.

Discussion

Comments

0 comments · new ones appear after approval

No comments yet. Be the first to share your thoughts.

Leave a comment

Your comment will be reviewed before it appears.