Integration guides

Flutter with Supabase

Complete path for a Flutter app with Supabase Auth and Supabase Edge Functions as the backend.

The login is Supabase Auth. The Supabase user ID (auth.users.id, the sub of the access token) is the externalUserId at Limenia (required for the Supabase connector).

Backend: Edge Functions (Deno)

Start from supabase-edge-functions/ of the examples repo: copy supabase/functions and supabase/migrations into your Supabase project.

Shell
supabase link --project-ref <your-project-ref>
supabase db push                       # creates the table limenia_webhook_events (RLS on, no policies)
supabase secrets set LIMENIA_API_KEY=… LIMENIA_WEBHOOK_SECRET=… DEVICE_CHECK_SECRET=…   # values typed by the user
supabase functions deploy limenia-reports
supabase functions deploy limenia-moderation-status
supabase functions deploy limenia-devices
supabase functions deploy limenia-webhook --no-verify-jwt   # Limenia sends no Supabase JWT; the signature authenticates
Function Calls Limenia
POST /functions/v1/limenia-reports POST /v1/reports, reporter from the user’s JWT, Idempotency-Key passed through or generated and echoed
GET /functions/v1/limenia-moderation-status GET /v1/subjects/{id}/status for the signed-in user only
POST /functions/v1/limenia-devices/request-hash, …/check POST /v1/devices/check
POST /functions/v1/limenia-webhook called by Limenia; Web Crypto HMAC over await req.arrayBuffer(), dedupe in limenia_webhook_events

The webhook function

The webhook URL is https://<project-ref>.supabase.co/functions/v1/limenia-webhook. The signature check (from _shared/signature.ts):

TypeScript
const rawBody = new Uint8Array(await req.arrayBuffer()); // never JSON.stringify(await req.json())
await verifySignature({ header: req.headers.get("limenia-signature"), rawBody, secrets: [LIMENIA_WEBHOOK_SECRET] });
// verifySignature: split at ",", t exactly once, v1 at least once, |now - t| <= 300,
// HMAC-SHA256(secret, `${t}.` + rawBody) via crypto.subtle, constant-time compare with every v1.

With LIMENIA_BAN_SUPABASE_USERS=true the example bans the Supabase user on ban_user (ban_duration: "876000h") and suspend_user, and lifts it ("none") on restore with restoreScope: "account" and on subject.status_changed to active or warned. Leave it off if you use Limenia’s Supabase connector.

Add complaints

Add a complaint function the same way as limenia-reports: forward to POST /v1/appeals (see Complaints), set appellant.externalUserId from the JWT, and remember appealId per user.

App: Flutter

Same packages as in the Firebase guide (without cloud_functions, with http and supabase_flutter). A transport over HTTP:

Dart
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:limenia/limenia.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

final class LimeniaSupabaseTransport implements LimeniaTransport {
  LimeniaSupabaseTransport({required this.functionsUrl, required this.anonKey, http.Client? client})
      : _http = client ?? http.Client();

  final String functionsUrl; // https://<project-ref>.supabase.co/functions/v1
  final String anonKey;      // the public anon key of the project, not a secret
  final http.Client _http;

  Map<String, String> _headers({String? idempotencyKey}) {
    final token = Supabase.instance.client.auth.currentSession?.accessToken;
    if (token == null) throw LimeniaException.fromResponse(status: 401); // waits in the queue until login
    return {
      'Authorization': 'Bearer $token',
      'apikey': anonKey,
      'Content-Type': 'application/json',
      if (idempotencyKey != null) 'Idempotency-Key': idempotencyKey,
    };
  }

  
  Future<ReportReceipt> createReport(ReportRequest request, {required String idempotencyKey}) async {
    final res = await _http
        .post(Uri.parse('$functionsUrl/limenia-reports'),
            headers: _headers(idempotencyKey: idempotencyKey), body: jsonEncode(request.toJson()))
        .timeout(const Duration(seconds: 60));
    return ReportReceipt.fromJson(_body(res));
  }

  
  Future<SubjectStatus> getSubjectStatus(String externalUserId) async {
    final res = await _http.get(Uri.parse('$functionsUrl/limenia-moderation-status'), headers: _headers());
    return SubjectStatus.fromJson(_body(res));
  }

  // createAppeal, getAppealStatus, createReview, getReviewStatus, createSignals, checkDevice:
  // the same pattern against your own functions (throw UnimplementedError until you add them).
  
  Future<AppealReceipt> createAppeal(AppealRequest request, {required String idempotencyKey}) =>
      throw UnimplementedError('add a limenia-appeals function');
  
  Future<AppealStatusInfo> getAppealStatus(String appealId) => throw UnimplementedError();
  
  Future<ReviewReceipt> createReview(ReviewRequest request, {required String idempotencyKey}) =>
      throw UnimplementedError();
  
  Future<ReviewStatusInfo> getReviewStatus(String reviewId) => throw UnimplementedError();
  
  Future<SignalsReceipt> createSignals(SignalsRequest request, {required String idempotencyKey}) =>
      throw UnimplementedError();
  
  Future<DeviceCheckResult> checkDevice(DeviceCheckRequest request) => throw UnimplementedError();

  JsonMap _body(http.Response res) {
    if (res.statusCode >= 200 && res.statusCode < 300) return jsonDecode(res.body) as JsonMap;
    throw LimeniaException.fromResponse(status: res.statusCode, body: res.body, retryAfter: res.headers['retry-after']);
  }
}

The rest of the app (report sheet, status, complaints, device check against limenia-devices/request-hash and limenia-devices/check with the returned ticket) works as in the Firebase guide.