diff --git a/ui/src/auth/login/index.tsx b/ui/src/auth/login/index.tsx index bca1e4a..a7bcf06 100644 --- a/ui/src/auth/login/index.tsx +++ b/ui/src/auth/login/index.tsx @@ -12,9 +12,9 @@ import { useForm } from "@mantine/form"; import { notifications } from "@mantine/notifications"; import * as MoghAuth from "mogh_auth_client"; import { AlertTriangle, KeyRound } from "lucide-react"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import LoginHeader from "./header"; -import { sanitizeQuery, useLogin, useLoginOptions } from "../.."; +import { authClient, sanitizeQuery, useLogin, useLoginOptions } from "../.."; export interface LoginBrandingProps { appName: string; @@ -41,6 +41,20 @@ export function LoginPage({ const [totpIsPending, setTotpPending] = useState(_totpIsPending ?? false); const secondFactorPending = passkeyIsPending || totpIsPending; + // Auto-redirect to OIDC provider if configured and disableAutoLogin is not set + useEffect(() => { + if ( + options?.oidc_auto_redirect && + options?.oidc && + !secondFactorPending + ) { + const params = new URLSearchParams(location.search); + if (!params.has("disableAutoLogin")) { + authClient().externalLogin("Oidc"); + } + } + }, [options?.oidc_auto_redirect, options?.oidc, secondFactorPending]); + // If signing in another user, need to redirect away from /login manually const maybeNavigate = location.pathname.startsWith("/login") ? () =>