Theia rip-out: - Delete app/api/theia-auth/route.ts (Traefik ForwardAuth shim) - Delete app/api/projects/[projectId]/workspace/route.ts and app/api/projects/prewarm/route.ts (Cloud Run Theia provisioning) - Delete lib/cloud-run-workspace.ts and lib/coolify-workspace.ts - Strip provisionTheiaWorkspace + theiaWorkspaceUrl/theiaAppUuid/ theiaError from app/api/projects/create/route.ts response - Remove Theia callbackUrl branch in app/auth/page.tsx - Drop "Open in Theia" button + xterm/Theia PTY copy in build/page.tsx - Drop theiaWorkspaceUrl from deployment/page.tsx Project type - Strip Theia IDE line + theia-code-os from advisor + agent-chat context strings - Scrub Theia mention from lib/auth/workspace-auth.ts comment P5.1 (custom apex domains + DNS): - lib/coolify.ts + lib/opensrs.ts: nameserver normalization, OpenSRS XML auth, Cloud DNS plumbing - scripts/smoke-attach-e2e.ts: full prod GCP + sandbox OpenSRS + prod Coolify smoke covering register/zone/A/NS/PATCH/cleanup In-progress (Justine onboarding/build, MVP setup, agent telemetry): - New (justine)/stories, project (home) layouts, mvp-setup, run, tasks routes + supporting components - Project shell + sidebar + nav refactor for the Stackless palette - Agent session API hardening (sessions, events, stream, approve, retry, stop) + atlas-chat, advisor, design-surfaces refresh - New scripts/sync-db-url-from-coolify.mjs + scripts/prisma-db-push.mjs + docker-compose.local-db.yml for local Prisma workflows - lib/dev-bypass.ts, lib/chat-context-refs.ts, lib/prd-sections.ts - Misc: stories CSS, debug/prisma route, modal-theme, BuildLivePlanPanel Made-with: Cursor
96 lines
3.0 KiB
TypeScript
96 lines
3.0 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { authSession } from "@/lib/auth/session-server";
|
|
import { query } from '@/lib/db-postgres';
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const session = await authSession();
|
|
if (!session?.user?.email) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
const { accessToken, githubUser } = await request.json();
|
|
if (!accessToken || !githubUser) {
|
|
return NextResponse.json({ error: 'Missing required fields' }, { status: 400 });
|
|
}
|
|
|
|
await query(
|
|
`UPDATE fs_users
|
|
SET data = data || $1::jsonb, updated_at = NOW()
|
|
WHERE data->>'email' = $2`,
|
|
[
|
|
JSON.stringify({
|
|
githubConnected: true,
|
|
githubUserId: githubUser.id,
|
|
githubUsername: githubUser.login,
|
|
githubName: githubUser.name,
|
|
githubEmail: githubUser.email,
|
|
githubAvatarUrl: githubUser.avatar_url,
|
|
githubAccessToken: accessToken,
|
|
githubConnectedAt: new Date().toISOString(),
|
|
}),
|
|
session.user.email,
|
|
]
|
|
);
|
|
|
|
return NextResponse.json({ success: true, githubUsername: githubUser.login });
|
|
} catch (error) {
|
|
console.error('[GitHub Connect] Error:', error);
|
|
return NextResponse.json({ error: 'Failed to store GitHub connection' }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function GET(request: Request) {
|
|
try {
|
|
const session = await authSession();
|
|
if (!session?.user?.email) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
const rows = await query<{ data: any }>(
|
|
`SELECT data FROM fs_users WHERE data->>'email' = $1 LIMIT 1`,
|
|
[session.user.email]
|
|
);
|
|
|
|
if (rows.length === 0 || !rows[0].data?.githubConnected) {
|
|
return NextResponse.json({ connected: false });
|
|
}
|
|
|
|
const d = rows[0].data;
|
|
return NextResponse.json({
|
|
connected: true,
|
|
githubUsername: d.githubUsername,
|
|
githubName: d.githubName,
|
|
githubAvatarUrl: d.githubAvatarUrl,
|
|
connectedAt: d.githubConnectedAt,
|
|
});
|
|
} catch (error) {
|
|
console.error('[GitHub Connect] Error:', error);
|
|
return NextResponse.json({ error: 'Failed to fetch GitHub connection' }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function DELETE(request: Request) {
|
|
try {
|
|
const session = await authSession();
|
|
if (!session?.user?.email) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
await query(
|
|
`UPDATE fs_users
|
|
SET data = data - 'githubConnected' - 'githubUserId' - 'githubUsername'
|
|
- 'githubName' - 'githubEmail' - 'githubAvatarUrl'
|
|
- 'githubAccessToken' - 'githubConnectedAt',
|
|
updated_at = NOW()
|
|
WHERE data->>'email' = $1`,
|
|
[session.user.email]
|
|
);
|
|
|
|
return NextResponse.json({ success: true });
|
|
} catch (error) {
|
|
console.error('[GitHub Disconnect] Error:', error);
|
|
return NextResponse.json({ error: 'Failed to disconnect GitHub' }, { status: 500 });
|
|
}
|
|
}
|