| ← All Docs Roles & Permissions

Roles & Permissions

Last updated Sep 2026 3 role types · 14 staff permission keys

Permission Matrix

Overview of what each role can access across the platform. Staff capabilities depend on per-member permission flags set by the dealer.

FeatureDealerStaffAdmin
Dashboard (if permitted) (platform-wide)
Create/Edit Bills (if permitted)
View Bills (read-only)
Cancel Bills (if permitted)
Collect Payments (if permitted)
Manage Farmers (if permitted) (view only)
Manage Products (if permitted)
Manage Inventory (if permitted)
Stock Purchases (if permitted)
Supplier Payments (if permitted)
Expenses (if permitted)
Cash Book / Daily Book (if permitted)
Cash Closing
Reports (Profit, Ageing)
Branch Management
Staff Management
Stock Transfers
Undo Transactions
Settings / ProfileOwn profile
WhatsApp Sending (if permitted)
Support TicketsManage
Subscription/PlansViewManage
Farmer Statements
Bill Returns (if permitted)
Farmer Discounts

Staff Permission Keys

Staff permissions are stored as a JSONB column on staff_members.permissions. Each key maps to one of three access modes:

When a dealer creates a new staff member, all keys default to the values shown below. The dealer can then toggle individual permissions from the Staff Management screen.

KeyControlsDefault
dashboardDashboard accesshidden
billHistoryView past billshidden
newBillCreate/edit billsvisible
farmerListView farmer listhidden
addFarmerAdd new farmersvisible
inventoryStock levelshidden
suppliersSupplier managementhidden
cashbookDaily bookhidden
expensesExpense trackinghidden
reportsReports sectionhidden
settingsShop settingshidden
branchesBranch managementhidden
staffManagementManage other staffhidden
transactionsPayment collectionvisible

Enforcement

Most staff permissions are enforced client-side only. However, cashbook and expenses are also enforced server-side: the staff_has_permission() SQL function is called within RLS policies to block access at the database level for those modules. Other modules remain client-side only — a technically savvy staff member could bypass those restrictions by directly querying the Supabase REST API.

Admin Roles

The admin portal supports three role levels. Admin accounts are managed separately from dealer/staff accounts and authenticate through their own portal.

RoleCapabilities
super_adminFull platform access. Create/delete admins, manage all dealers, subscriptions, system configuration, view all data.
supportView-only access to dealer data, ticket resolution, no write operations on dealer data.
salesOnboarding new dealers, subscription management, limited dealer data access for demos.

RLS Enforcement

Row Level Security (RLS) is the primary data isolation mechanism in AquaDealers. It ensures that every database query is scoped to the authenticated user's tenant.

Tenant Isolation. RLS policies ensure complete tenant isolation. A dealer can never access another dealer's data, even through direct API calls.

Authentication Flow

Dealer Auth

  1. Supabase Auth (email/password or OTP)
  2. JWT stored in browser, auto-refreshed by Supabase client
  3. Optional app-lock PIN (verified via verify_dealer_pin RPC)

Staff Auth

  1. Staff enters phone number + 4-digit PIN on the staff portal
  2. staff_portal_login RPC verifies the PIN against a bcrypt hash
  3. Custom token issued (not a Supabase JWT)
  4. Token stored in sessionStorage, expires in 4 hours
  5. Rate limited: 8 failed attempts per 15 minutes

Admin Auth

  1. Email + password on the admin portal
  2. bcrypt verification, custom session token issued
  3. Session expires in 4 hours