Files
app/app/api/nodes/debug/route.ts
Albert d072b71eec refactor: Improve debug panel delete handler and add debug endpoint
- Refactored UserMenu debug panel delete handler to match ThoughtGalaxy pattern
- Added proper error handling with Mantine notifications
- Added loading state management during delete operations
- Created /api/nodes/debug endpoint for development debugging
- Cleaned up debug logging from DELETE endpoint

The debug panel now uses the same delete pattern as ThoughtGalaxy for consistency,
with proper error notifications and state updates.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 02:32:34 +00:00

67 lines
1.9 KiB
TypeScript

import { NextResponse } from 'next/server';
import { cookies } from 'next/headers';
import { connectToDB } from '@/lib/db';
import { verifySurrealJwt } from '@/lib/auth/jwt';
/**
* GET /api/nodes/debug
*
* Debug endpoint to list all nodes for the current user in SurrealDB.
* Only available in development mode.
*/
export async function GET() {
// Only allow in development
if (process.env.NODE_ENV !== 'development') {
return NextResponse.json({ error: 'Not available in production' }, { status: 403 });
}
const cookieStore = await cookies();
const surrealJwt = cookieStore.get('ponderants-auth')?.value;
console.log('[DEBUG /api/nodes/debug] Auth check:', {
hasSurrealJwt: !!surrealJwt,
});
if (!surrealJwt) {
console.error('[DEBUG /api/nodes/debug] Missing auth cookie');
return NextResponse.json({ error: 'Not authenticated' }, { status: 401 });
}
// Verify the JWT and extract user info
const userSession = verifySurrealJwt(surrealJwt);
if (!userSession) {
console.error('[DEBUG /api/nodes/debug] Invalid JWT');
return NextResponse.json({ error: 'Invalid auth token' }, { status: 401 });
}
const { did: userDid } = userSession;
try {
const db = await connectToDB();
// Fetch ALL nodes for this user (no filters)
const nodesResult = await db.query<
[Array<{ id: string; title: string; body: string; user_did: string; atp_uri: string }>]
>('SELECT id, title, body, user_did, atp_uri FROM node WHERE user_did = $userDid', {
userDid,
});
const nodes = nodesResult[0] || [];
console.log('[DEBUG /api/nodes/debug] Found nodes:', {
count: nodes.length,
userDid,
nodeIds: nodes.map((n) => n.id),
});
return NextResponse.json({
nodes,
userDid,
count: nodes.length,
});
} catch (error) {
console.error('[DEBUG /api/nodes/debug] Error:', error);
return NextResponse.json({ error: 'Failed to fetch nodes' }, { status: 500 });
}
}