import { NextResponse } from "next/server";

import {
  getAuthenticatedPrincipal,
  getUserAccessProfile,
} from "@/lib/authorization";

export async function GET(request: Request) {
  const auth = await getAuthenticatedPrincipal(request);

  if (!auth.ok) {
    return auth.response;
  }

  const access = await getUserAccessProfile(auth.principal);

  return NextResponse.json({
    message: "Authenticated user retrieved",
    user: {
      ...auth.principal,
      access,
    },
  });
}
