Backend (make everything real, no stubs): - Implement all 10 Python engine scripts (scispacy, pymare, pytrials, minicheck, indra, openalex, paperqa, pykeen, storm, asreview) behind the existing lib/engines bridges. openalex + pytrials are zero-dep (stdlib urllib, work out of the box); the 8 heavy engines run the real library when installed and emit an honest structured error envelope when absent — no phantom capability, no faked outputs. - /api/verify: hard production guard so the offline fixture path can NEVER activate in production (MOCK_MODE gated to NODE_ENV!=production); prod always runs the real retrieve→extract→verify pipeline. - /api/auth/google: wrap the OAuth entrypoint in try/catch — fail closed to /login. - MoA: wire the previously-dangling design_priors artifact into the multivers cross-source verifier as a mean-preserving, clamped (+/-25%) design-credibility weight; exact no-op when absent, so the benchmark verdict mix is protected. Frontend (enterprise-grade polish): - New shared console UI kit (components/console/ui.tsx): Skeleton, Card, Badge, Button, StatCard, EmptyState — one source for the house tokens. - Skeleton shimmer keyframe; LoadingBanner now renders shimmer instead of plain text (propagates to ~29 tool pages, signature unchanged). - Real workspace overview landing page: live stats (fixes a phantom 'claims' field the old page always rendered as 0), recent verifications with permalinks, quick actions, skeleton loading + empty + error states. Verified: tsc clean, 10/10 verify integration tests pass, production build compiles all 417 pages.
44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { cookies } from "next/headers";
|
|
import { isGoogleConfigured, buildGoogleAuthUrl } from "@/lib/auth/google";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
// GET /api/auth/google — start the Google OAuth flow. Generates a CSRF state,
|
|
// stashes it in a short-lived httpOnly cookie, and redirects to Google's consent
|
|
// screen. The callback verifies the state before trusting the code.
|
|
const STATE_COOKIE = "pt_oauth_state";
|
|
|
|
export async function GET(req: NextRequest): Promise<Response> {
|
|
const origin = req.nextUrl.origin;
|
|
const loginUrl = new URL("/login", origin);
|
|
|
|
try {
|
|
if (!isGoogleConfigured()) {
|
|
loginUrl.searchParams.set("error", "google_not_configured");
|
|
return NextResponse.redirect(loginUrl);
|
|
}
|
|
|
|
const state = crypto.randomUUID();
|
|
const redirectUri = `${origin}/api/auth/google/callback`;
|
|
const authUrl = buildGoogleAuthUrl(redirectUri, state);
|
|
|
|
const store = await cookies();
|
|
store.set(STATE_COOKIE, state, {
|
|
httpOnly: true,
|
|
secure: process.env.NODE_ENV === "production",
|
|
sameSite: "lax",
|
|
path: "/",
|
|
maxAge: 600, // 10 minutes to complete the round-trip
|
|
});
|
|
|
|
return NextResponse.redirect(authUrl);
|
|
} catch (err) {
|
|
// Never leave the OAuth entrypoint able to throw an unhandled 500 (e.g. a cookie
|
|
// store failure in an edge runtime): fail closed back to /login with a generic error.
|
|
console.error("[/api/auth/google] failed to start OAuth flow:", err);
|
|
loginUrl.searchParams.set("error", "google_start_failed");
|
|
return NextResponse.redirect(loginUrl);
|
|
}
|
|
}
|