Skip to main content

Supabase Session Tracking Guide

This guide explains how to track research session progress using the research_sessions table in Supabase, enabling live progress updates and session history in your Next.js frontend.

Overview

The Deep Research API logs session progress to Supabase’s research_sessions table:
  • Live progress tracking - See current phase and tool call counts
  • Resume after disconnect - Reconnect and see where the analysis is
  • Session history - View past research sessions
  • Supabase Realtime - Subscribe to live updates without polling

Table Schema

Frontend Integration (Next.js)

1. Install Supabase Client

2. Create Supabase Client

3. Session Types


Option 1: Polling (Simple)

Use polling to check session status at regular intervals:

Usage in Component


Subscribe to real-time updates for instant progress tracking:

Enable Realtime in Supabase

Run this SQL in Supabase Dashboard:

Fetching Session History

Get past sessions for a user:

Session History Component


Check for Active Sessions

Before starting a new analysis, check if user has one running:

Resume Active Session


Best Practices

  1. Use Realtime for active sessions - Polling wastes resources
  2. Stop polling when complete - Check status before next poll
  3. Handle disconnects gracefully - Show last known state
  4. Cache session history - Use React Query or SWR
  5. Implement timeout detection - Check last_activity_at for stale sessions

Troubleshooting