// ── Auth: Current User ──────────────────────────────────────────────────────
// GET /api/auth/me
// Returns the authenticated user's profile from the current session. Used by
// the front-end to validate tokens and hydrate user context on load.
// Returns 401 if no valid session exists.

import { NextResponse } from "next/server"
import { getSessionUser } from "@/lib/auth"

// ── GET ──────────────────────────────────────────────────────────────────────

export async function GET() {
  try {
    const user = await getSessionUser()
    if (!user) {
      return NextResponse.json({ error: "Not authenticated." }, { status: 401 })
    }
    return NextResponse.json({ user }, { status: 200 })
  } catch (error) {
    console.error("Auth me error:", error)
    return NextResponse.json(
      { error: "Authentication service unavailable." },
      { status: 503 }
    )
  }
}
