Skip to main content

Overview

The auto-deactivate edge function automatically deactivates check-in pages and attendee portals for events that have ended. This function is designed to be triggered by super admins to maintain system hygiene and security.
This function requires super_admin role. Only authorized platform administrators can trigger auto-deactivation.

Endpoint

POST /functions/v1/auto-deactivate

Authentication

Requires a valid Bearer token with super_admin role.
Authorization: Bearer <supabase_access_token>

Deactivation Logic

The function performs two types of deactivation:
  1. Check-in Pages: Deactivated for events that ended more than 1 day ago
  2. Attendee Portals: Deactivated for events that ended more than 3 days ago

Request

No request body is required. The function automatically processes all eligible events.

Example Request

curl -X POST 'https://<project-ref>.supabase.co/functions/v1/auto-deactivate' \
  -H 'Authorization: Bearer <super_admin_token>' \
  -H 'Content-Type: application/json'

Response

Success Response (200 OK)

checkin_pages_deactivated
number
Number of check-in pages that were deactivated
portals_deactivated
number
Number of attendee portals that were deactivated
timestamp
string
ISO 8601 timestamp of when the operation completed
{
  "checkin_pages_deactivated": 5,
  "portals_deactivated": 12,
  "timestamp": "2026-03-04T10:30:00.000Z"
}

Error Responses

401 Unauthorized

Returned when the Bearer token is missing or invalid.
{
  "error": "Unauthorized"
}

403 Forbidden

Returned when the authenticated user does not have super_admin role.
{
  "error": "Forbidden"
}

500 Internal Server Error

Returned when the deactivation process fails.
{
  "error": "Auto-deactivation failed"
}

Implementation Details

Check-in Page Deactivation

From source/supabase/functions/auto-deactivate/index.ts:60-69:
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000)
  .toISOString().split("T")[0];

const { data: expiredCheckinEvents } = await adminClient
  .from("events")
  .update({ checkin_page_active: false })
  .eq("checkin_page_active", true)
  .lt("date", oneDayAgo)
  .select("id, name, organization_id");

Attendee Portal Deactivation

From source/supabase/functions/auto-deactivate/index.ts:72-92:
const threeDaysAgo = new Date(now.getTime() - 3 * 24 * 60 * 60 * 1000)
  .toISOString().split("T")[0];

const { data: expiredPortalEvents } = await adminClient
  .from("events")
  .select("id, name, organization_id")
  .lt("date", threeDaysAgo);

if (expiredPortalEvents && expiredPortalEvents.length > 0) {
  const eventIds = expiredPortalEvents.map((e) => e.id);
  
  const { data: updated } = await adminClient
    .from("attendees")
    .update({ portal_active: false })
    .in("event_id", eventIds)
    .eq("portal_active", true)
    .select("id");
  
  portalsDeactivated = updated?.length ?? 0;
}

Use Cases

  • Scheduled Cleanup: Run via cron job to automatically clean up expired events
  • Manual Trigger: Super admin can manually trigger cleanup as needed
  • Security: Prevents access to check-in pages and attendee portals after events conclude
  • Data Hygiene: Maintains clean system state by deactivating old event resources

Build docs developers (and LLMs) love