From 2226b3a117f589bb611a0613a2213f7a8c40cda1 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Sun, 5 Apr 2026 00:48:58 -0400 Subject: [PATCH 1/3] Add OIDC auto-redirect to LoginPage When oidc_auto_redirect is set in login options, automatically redirect unauthenticated users to the OIDC provider instead of showing the login page. Users can bypass by appending ?disableAutoLogin to the login URL. --- ui/src/auth/login/index.tsx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ui/src/auth/login/index.tsx b/ui/src/auth/login/index.tsx index bca1e4a..250fd4b 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, useRef, 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,23 @@ 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 + const autoRedirectTriggered = useRef(false); + useEffect(() => { + if ( + options?.oidc_auto_redirect && + options?.oidc && + !autoRedirectTriggered.current && + !secondFactorPending + ) { + const params = new URLSearchParams(location.search); + if (!params.has("disableAutoLogin")) { + autoRedirectTriggered.current = true; + authClient().externalLogin("Oidc"); + } + } + }, [options, secondFactorPending]); + // If signing in another user, need to redirect away from /login manually const maybeNavigate = location.pathname.startsWith("/login") ? () => From 1c7ced34075b5435d51fd5dfa17f9c63e6eda73e Mon Sep 17 00:00:00 2001 From: John Maguire Date: Mon, 13 Apr 2026 00:30:32 -0400 Subject: [PATCH 2/3] Add booleans to dependency array --- ui/src/auth/login/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/auth/login/index.tsx b/ui/src/auth/login/index.tsx index 250fd4b..fb638f9 100644 --- a/ui/src/auth/login/index.tsx +++ b/ui/src/auth/login/index.tsx @@ -56,7 +56,7 @@ export function LoginPage({ authClient().externalLogin("Oidc"); } } - }, [options, secondFactorPending]); + }, [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") From 0c13fa032404506f76a503e7c06039ea722cda3d Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 16 Apr 2026 12:48:45 -0400 Subject: [PATCH 3/3] useRef --- ui/src/auth/login/index.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ui/src/auth/login/index.tsx b/ui/src/auth/login/index.tsx index fb638f9..a7bcf06 100644 --- a/ui/src/auth/login/index.tsx +++ b/ui/src/auth/login/index.tsx @@ -12,7 +12,7 @@ import { useForm } from "@mantine/form"; import { notifications } from "@mantine/notifications"; import * as MoghAuth from "mogh_auth_client"; import { AlertTriangle, KeyRound } from "lucide-react"; -import { useEffect, useRef, useState } from "react"; +import { useEffect, useState } from "react"; import LoginHeader from "./header"; import { authClient, sanitizeQuery, useLogin, useLoginOptions } from "../.."; @@ -42,17 +42,14 @@ export function LoginPage({ const secondFactorPending = passkeyIsPending || totpIsPending; // Auto-redirect to OIDC provider if configured and disableAutoLogin is not set - const autoRedirectTriggered = useRef(false); useEffect(() => { if ( options?.oidc_auto_redirect && options?.oidc && - !autoRedirectTriggered.current && !secondFactorPending ) { const params = new URLSearchParams(location.search); if (!params.has("disableAutoLogin")) { - autoRedirectTriggered.current = true; authClient().externalLogin("Oidc"); } }