Skip to content

Add OIDC auto-redirect to LoginPage#3

Open
johnmaguire wants to merge 3 commits intomoghtech:mainfrom
johnmaguire:oidc-auto-redirect-ui
Open

Add OIDC auto-redirect to LoginPage#3
johnmaguire wants to merge 3 commits intomoghtech:mainfrom
johnmaguire:oidc-auto-redirect-ui

Conversation

@johnmaguire
Copy link
Copy Markdown
Contributor

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.

Requires moghtech/komodo#1339 to enable

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.
Comment thread ui/src/auth/login/index.tsx Outdated
const secondFactorPending = passkeyIsPending || totpIsPending;

// Auto-redirect to OIDC provider if configured and disableAutoLogin is not set
const autoRedirectTriggered = useRef(false);
Copy link
Copy Markdown
Member

@mbecker20 mbecker20 Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it need to store whether auto redirect has been triggered?

Copy link
Copy Markdown
Contributor Author

@johnmaguire johnmaguire Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not be strictly necessary, it just prevents calling redirect twice if a dependency changes. (React dev in Strict Mode calls useEffect twice, as well.) Can remove it if you prefer. 🤷

Copy link
Copy Markdown
Member

@mbecker20 mbecker20 Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the first redirect moves client away from this page, the useEffect won't run again because client now on another page

Copy link
Copy Markdown
Contributor Author

@johnmaguire johnmaguire Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it's to prevent a race condition where, before the page has unloaded due to the redirect, render is called again. This is possible because the redirect caused by location.replace() is an asynchronous operation - JS will continue to execute until the page is unloaded.

This could create two redirects in the local browser. The "worst case scenario" here is an extra HTTP request that the user likely doesn't notice. It's really just a matter of correctness, to satisfy things like linters, and React strict mode.

I have absolutely zero strong opinions on this matter. Removed the useRef.

Comment thread ui/src/auth/login/index.tsx Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants