Fix missing OIDC button: stop static-prerendering /login

/login was prerendered at Docker build time when AUTH_OIDC_* were
unset, baking oidcEnabled=false into the page. Force dynamic render
and also read /api/v1/auth/config on the client as a fallback.
This commit is contained in:
Cursor Agent
2026-08-24 04:02:37 +00:00
parent cd1a2fe808
commit f2de0e3892
2 changed files with 31 additions and 4 deletions
+4
View File
@@ -1,6 +1,10 @@
import { isOidcConfigured } from "@/lib/auth/oidc";
import { LoginPageClient } from "@/components/LoginPageClient";
// OIDC env is only available at runtime (Docker). Never prerender this page
// at build time or the SSO button stays permanently hidden.
export const dynamic = "force-dynamic";
export default function LoginPage() {
const authUrl = (process.env.AUTH_URL || "").replace(/\/$/, "");
const callbackUrlHint = authUrl
+27 -4
View File
@@ -1,6 +1,6 @@
"use client";
import { FormEvent, useState } from "react";
import { FormEvent, useEffect, useState } from "react";
import { signIn } from "next-auth/react";
import { useRouter, useSearchParams } from "next/navigation";
import { Suspense } from "react";
@@ -11,6 +11,12 @@ type Props = {
callbackUrlHint: string;
};
type AuthConfig = {
oidcEnabled: boolean;
oidcName: string;
callbackUrl: string;
};
function authErrorMessage(code: string | null): string | null {
if (!code) return null;
switch (code) {
@@ -40,6 +46,23 @@ function LoginForm({ oidcEnabled, oidcName, callbackUrlHint }: Props) {
authErrorMessage(params.get("error"))
);
const [loading, setLoading] = useState(false);
const [runtimeOidc, setRuntimeOidc] = useState<AuthConfig | null>(null);
// Belt-and-suspenders: ask the live API so a stale static shell can't hide SSO
useEffect(() => {
fetch("/api/v1/auth/config")
.then((r) => (r.ok ? r.json() : null))
.then((data: AuthConfig | null) => {
if (data) setRuntimeOidc(data);
})
.catch(() => {
/* ignore */
});
}, []);
const showOidc = runtimeOidc?.oidcEnabled ?? oidcEnabled;
const displayName = runtimeOidc?.oidcName || oidcName;
const redirectHint = runtimeOidc?.callbackUrl || callbackUrlHint;
async function onSubmit(e: FormEvent) {
e.preventDefault();
@@ -97,19 +120,19 @@ function LoginForm({ oidcEnabled, oidcName, callbackUrlHint }: Props) {
<button className="btn" type="submit" disabled={loading}>
{loading ? "Signing in…" : "Sign in"}
</button>
{oidcEnabled && (
{showOidc && (
<>
<button
type="button"
className="btn btn-secondary"
onClick={() => signIn("oidc", { callbackUrl })}
>
Sign in with {oidcName}
Sign in with {displayName}
</button>
<p className="muted" style={{ margin: 0, fontSize: "0.75rem" }}>
IdP redirect URI must be exactly:
<br />
<code className="mono">{callbackUrlHint}</code>
<code className="mono">{redirectHint}</code>
</p>
</>
)}