import { NextResponse } from "next/server";
import { HttpError } from "@/lib/auth/authContext";
import { getAuthedConvexClient } from "@/lib/convex/route";

export const dynamic = "force-dynamic";

export async function GET() {
  try {
    const { auth } = await getAuthedConvexClient();
    return NextResponse.json({
      userId: auth.userId,
      email: auth.email ?? null,
      name: auth.name ?? null,
    });
  } catch (err) {
    if (err instanceof HttpError) {
      return NextResponse.json({ error: "未登录" }, { status: err.status });
    }
    return NextResponse.json({ error: "未登录" }, { status: 401 });
  }
}

