Supabase Integration - arilonUK/iotagentmesh GitHub Wiki
Overview
Supabase is used as the backend-as-a-service for authentication, database (PostgreSQL), authorization via RLS, and edge functions.
Client Setup
- Initialized in
lib/supabaseClient.ts - Uses
createClient(SUPABASE_URL, SUPABASE_ANON_KEY)
Auth
- User registration, login, password recovery
- Auth state is monitored with Supabase's
onAuthStateChange - JWT is stored in browser (localStorage)
Row-Level Security (RLS)
- Policies ensure data isolation by organisation and user roles
Functions
- Edge Functions (planned) for data aggregation, ping, webhook forwarding
Database Schema
Tables
1. users
id: UUID (PK)email: textcreated_at: timestamp
2. organisations
id: UUID (PK)name: textcreated_by: UUID (FK to users)created_at: timestamp
3. organisation_members
id: UUID (PK)user_id: UUID (FK)organisation_id: UUID (FK)role: text ("admin", "viewer")joined_at: timestamp
4. devices
id: UUID (PK)organisation_id: UUID (FK)name: textstatus: text ("online", "offline")location: textlast_seen: timestamp
5. device_events
id: UUID (PK)device_id: UUID (FK)event_type: text ("telemetry", "alert")payload: jsonbcreated_at: timestamp
Views (planned)
active_devices_per_orglatest_device_event
RLS Policies
- Enforced on all tables based on authenticated user ID and membership
- Only members of an org can access its devices and events
RPC Functions (planned)
record_device_ping(device_id)aggregate_telemetry(device_id, range)