import { signIn } from "@/auth";

/**
 * Auto-redirect to Keycloak. We have exactly one auth provider, so
 * skip NextAuth's provider-list page at /api/auth/signin — the kit's
 * middleware (signInPath: "/auth/keycloak") and the NextAuth config
 * (pages.signIn) both point here.
 */
export async function GET(request: Request) {
  const url = new URL(request.url);
  const callbackUrl = url.searchParams.get("callbackUrl") || "/";
  await signIn("keycloak", { redirectTo: callbackUrl });
  return new Response(null, { status: 302, headers: { Location: callbackUrl } });
}
