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
users
1. id
: UUID (PK)email
: textcreated_at
: timestamp
organisations
2. id
: UUID (PK)name
: textcreated_by
: UUID (FK to users)created_at
: timestamp
organisation_members
3. id
: UUID (PK)user_id
: UUID (FK)organisation_id
: UUID (FK)role
: text ("admin", "viewer")joined_at
: timestamp
devices
4. id
: UUID (PK)organisation_id
: UUID (FK)name
: textstatus
: text ("online", "offline")location
: textlast_seen
: timestamp
device_events
5. id
: UUID (PK)device_id
: UUID (FK)event_type
: text ("telemetry", "alert")payload
: jsonbcreated_at
: timestamp
Views (planned)
active_devices_per_org
latest_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)