Skip to content

Latest commit

Β 

History

History
105 lines (80 loc) Β· 2.03 KB

debug-guide.md

File metadata and controls

105 lines (80 loc) Β· 2.03 KB

πŸ› Debug Guide

Last Updated: 2026-03-15 | Version: 1.5.0

πŸ” Debugging API Routes

Method 1: Console Logs

export async function POST(req: Request) {
  console.log('πŸ“₯ Request received:', new Date().toISOString());
  const body = await req.json();
  console.log('πŸ“¦ Body:', JSON.stringify(body, null, 2));
  
  // ... rest of handler
}

View logs: npm run dev terminal output.

Method 2: VS Code Debugger

Create .vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Next.js: debug server-side",
      "type": "node-terminal",
      "request": "launch",
      "command": "npm run dev"
    },
    {
      "name": "Next.js: debug client-side",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:3000"
    }
  ]
}

πŸ—„οΈ Debugging Database Queries

Enable Prisma query logging:

// src/lib/database.ts
export const prisma = new PrismaClient({
  log: process.env.NODE_ENV === 'development' 
    ? ['query', 'error', 'warn'] 
    : ['error'],
});

This logs all SQL queries to the terminal.


πŸ”„ Debugging Sync Issues

// Add verbose logging to sync service
async function syncPlatform(userId: string, platform: UserPlatform) {
  console.log(`πŸ”„ Syncing ${platform.platform.name} for user ${userId}`);
  
  try {
    const result = await scraper.scrape(config);
    console.log(`βœ… Scraped ${result.length} entries`);
    return result;
  } catch (error) {
    console.error(`❌ Sync failed for ${platform.platform.name}:`, error);
    throw error;
  }
}

πŸ”‘ Debugging Auth Issues

// Temporary: Log session in API route
export async function GET(req: Request) {
  const session = await getServerSession(authOptions);
  console.log('Session:', JSON.stringify(session, null, 2));
  // ...
}

Or check NextAuth debug mode:

NEXTAUTH_DEBUG=true

πŸ“Ž Related Docs