TRVLR Sync
TRVLR Sync provides backend functionality for syncing Bungie OAuth accounts and Destiny manifest data using Supabase Edge Functions and PostgreSQL. This service enables seamless integration between Destiny 2 game data and external applications.Overview
TRVLR Sync handles Bungie.net OAuth authentication, stores Destiny 2 manifest data, and provides APIs for accessing character data, inventory, loadouts, and vendor information. The service supports both JSON and SQLite manifest storage formats.Key Features
- Bungie OAuth Integration: Custom PKCE handshake and secure token storage
- Manifest Management: Dual storage options (PostgreSQL JSON and S3 SQLite)
- Character Data Sync: Real-time synchronization of Destiny 2 character data
- Inventory Management: Track and manage in-game inventory
- Loadout Builder: Create and manage character loadouts
- Vendor Tracking: Monitor vendor inventories and rewards
Architecture
Technology Stack
- Frontend: Next.js 15, TypeScript, React
- Backend: Supabase Edge Functions, PostgreSQL
- Storage: Supabase Storage (S3-compatible) for SQLite manifests
- Authentication: Bungie.net OAuth 2.0 with PKCE
- Database: PostgreSQL with Row Level Security (RLS)
- Deployment: Vercel (frontend), Supabase (backend)
Application Structure
Getting Started
Prerequisites
- Node.js 18+ and pnpm
- Supabase CLI (>= v2.20.x)
- Bungie.net API credentials
- OpenSSL (for local HTTPS certificates)
Setup
-
Navigate to application directory:
-
Install dependencies:
-
Generate SSL certificates (for local HTTPS):
-
Configure environment variables:
Create
.env.local: -
Start Supabase locally:
-
Apply database migrations:
-
Run development server:
Bungie OAuth Flow
TRVLR Sync implements a custom PKCE (Proof Key for Code Exchange) OAuth flow:- Initiate OAuth: User clicks “Connect Bungie Account”
- PKCE Generation: Server generates code verifier and challenge
- Redirect to Bungie: User authenticates with Bungie.net
- Callback Handling: Server receives authorization code
- Token Exchange: Exchange code for access/refresh tokens
- Token Storage: Store tokens securely in
bungie_accountstable
Edge Functions
bungie-auth/init.ts: Initiates PKCE handshake and redirects to Bungie OAuthbungie-auth/callback.ts: Handles OAuth callback and token storage
Manifest Management
TRVLR Sync supports two manifest storage formats:JSON Storage (PostgreSQL)
- Stored directly in
destiny_manifesttable - Fast queries with PostgreSQL indexing
- Suitable for frequently accessed data
SQLite Storage (S3)
- Stored in Supabase Storage (S3-compatible)
- Metadata tracked in
manifest_filestable - Suitable for large manifest files
Manifest Sync
Thesync-manifest Edge Function:
- Fetches latest manifest from Bungie API
- Stores JSON version in PostgreSQL
- Stores SQLite version in S3 (if enabled)
- Updates manifest metadata
Database Schema
Tables
bungie_accounts: Stores OAuth tokens and account metadatadestiny_manifest: JSON manifest datamanifest_files: SQLite manifest file metadata
API Endpoints
Authentication
GET /api/auth/bungie/login- Initiate OAuth flowGET /api/auth/bungie/callback- Handle OAuth callback
Manifest
GET /api/manifest- Get current manifest versionPOST /api/manifest/sync- Trigger manifest sync
Character Data
GET /api/characters- Get user’s charactersGET /api/inventory- Get character inventoryGET /api/loadouts- Get saved loadouts
Deployment
Environment Variables
| Variable | Description | Required |
|---|---|---|
NEXT_PUBLIC_SUPABASE_URL | Supabase project URL | Yes |
NEXT_PUBLIC_SUPABASE_ANON_KEY | Supabase anonymous key | Yes |
BUNGIE_CLIENT_ID | Bungie.net OAuth client ID | Yes |
BUNGIE_CLIENT_SECRET | Bungie.net OAuth client secret | Yes |
BUNGIE_API_KEY | Bungie.net API key | Yes |
Vercel Deployment
- Connect repository to Vercel
- Set environment variables
- Configure Supabase Edge Functions separately
- Deploy frontend application
Troubleshooting
Common Issues
SSL Certificate Errors
- Issue: “Certificate verification failed” when connecting to local Supabase
- Solution: Ensure SSL certificates are generated correctly and paths are correct in environment variables.
OAuth Callback Failures
- Issue: OAuth callback not working or redirecting incorrectly
- Solution: Verify
APP_URLandNEXT_PUBLIC_SITE_URLmatch your local development URL. Check Bungie API credentials.
Manifest Sync Failures
- Issue: Manifest sync not completing or errors during sync
- Solution: Check Bungie API key validity. Verify database connection and storage permissions. Review Edge Function logs.
Performance Tips
- Use JSON Storage: For frequently accessed data, use PostgreSQL JSON storage
- Use SQLite Storage: For large manifest files, use S3-compatible storage
- Schedule Syncs: Use scheduled Edge Functions to keep manifest up-to-date
- Cache Responses: Implement caching for manifest queries
Related Resources
- Bungie API Documentation - Bungie.net API reference
- Supabase Edge Functions - Function development
- Database Migrations - Migration patterns
- Supabase Client Package - Database client utilities
- Supabase S3 Access - S3-compatible storage setup