fix: retire legacy Firebase session tracking endpoint

Returns 410 Gone instead of crashing with adminDb.collection errors.
Was flooding logs with TypeError on every call from the old Cursor extension.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-02-19 15:26:12 -08:00
parent 783700a7db
commit 81cca70542

View File

@@ -1,112 +1,11 @@
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
import { adminDb } from '@/lib/firebase/admin';
import { FieldValue, Timestamp } from 'firebase-admin/firestore';
export async function POST(request: Request) { // This endpoint was part of the legacy Cursor extension + Firebase integration.
try { // Firebase has been fully removed — return 410 Gone so callers know to stop.
const body = await request.json(); export async function POST() {
const { apiKey, sessionData } = body;
if (!apiKey) {
return NextResponse.json( return NextResponse.json(
{ error: 'API key is required' }, { error: 'This endpoint is no longer active. Session tracking has been deprecated.' },
{ status: 401 } { status: 410 },
); );
} }
// Verify API key and get userId
const keyDoc = await adminDb.collection('apiKeys').doc(apiKey).get();
if (!keyDoc.exists || !keyDoc.data()?.isActive) {
return NextResponse.json(
{ error: 'Invalid or inactive API key' },
{ status: 401 }
);
}
const userId = keyDoc.data()!.userId;
if (!userId) {
return NextResponse.json(
{ error: 'User not found for API key' },
{ status: 401 }
);
}
// Update last used timestamp
await keyDoc.ref.update({
lastUsed: FieldValue.serverTimestamp(),
});
// Check if workspace has an associated project
let projectId = sessionData.projectId || null;
let needsProjectAssociation = false;
if (!projectId && sessionData.workspacePath) {
// Try to find a project with this workspace path
const projectsSnapshot = await adminDb
.collection('projects')
.where('userId', '==', userId)
.where('workspacePath', '==', sessionData.workspacePath)
.limit(1)
.get();
if (!projectsSnapshot.empty) {
// Found a matching project, auto-associate
projectId = projectsSnapshot.docs[0].id;
console.log(`✅ Auto-associated session with project: ${projectId}`);
} else {
// No matching project found, flag for user action
needsProjectAssociation = true;
console.log(`⚠️ New workspace detected: ${sessionData.workspacePath}`);
}
}
// Create session document
const sessionRef = adminDb.collection('sessions').doc();
await sessionRef.set({
id: sessionRef.id,
userId,
projectId,
// Session data
startTime: Timestamp.fromMillis(new Date(sessionData.startTime).getTime()),
endTime: sessionData.endTime ? Timestamp.fromMillis(new Date(sessionData.endTime).getTime()) : null,
duration: sessionData.duration || null,
// Project context
workspacePath: sessionData.workspacePath || null,
workspaceName: sessionData.workspacePath ? sessionData.workspacePath.split('/').pop() : null,
needsProjectAssociation,
// AI usage
model: sessionData.model || 'unknown',
tokensUsed: sessionData.tokensUsed || 0,
cost: sessionData.cost || 0,
// Context
filesModified: sessionData.filesModified || [],
conversationSummary: sessionData.conversationSummary || null,
conversation: sessionData.conversation || [],
messageCount: sessionData.conversation?.length || 0,
createdAt: FieldValue.serverTimestamp(),
});
return NextResponse.json({
success: true,
sessionId: sessionRef.id,
message: 'Session tracked successfully',
});
} catch (error) {
console.error('Error tracking session:', error);
return NextResponse.json(
{
error: 'Failed to track session',
details: error instanceof Error ? error.message : String(error),
},
{ status: 500 }
);
}
}