feat: add auto login to skip sign-in method chooser

If you combine OIDC with local accounts or if your OIDC provider is an
external company (Facebook, GitHub, …) it makes sense for HedgeDoc to
show a additional login modal so users know that they will leave the
page.

However, if OAuth2/OIDC is a deployment's primary sign-in method and a
local OIDC provider is being used, users expect the common SSO method
being used, and he "Choose method" modal is a redundant extra click.
Essentially, you may have to click login thrice:

- Click login -> modal opens
- Click Login with provider -> provider login opens
- Log in (unless you are logged in already)

This simple patch adds an auto-login configuration, which makes the Sign
In button link straight to the provider's OAuth2 flow, improving the UX
of tHedgeDoc's login.

Signed-off-by: Lars Kiesow <lkiesow@uos.de>
This commit is contained in:
Lars Kiesow
2026-07-10 23:29:16 +02:00
committed by Philip Molares
parent ed7f374434
commit d05cfe4e9f
3 changed files with 25 additions and 2 deletions

9
app.js
View File

@@ -253,6 +253,15 @@ app.locals.authProviders = {
allowEmailRegister: config.allowEmailRegister
}
// If none of the form-based methods (LDAP, Email, OpenID) are configured and
// exactly one redirect-style external provider is, skip the "Choose method"
// dialog and link "Sign In" straight to that provider's login page.
const externalProviderKeys = ['facebook', 'twitter', 'github', 'gitlab', 'mattermost', 'dropbox', 'google', 'saml', 'oauth2']
const enabledExternalProviders = externalProviderKeys.filter((key) => app.locals.authProviders[key])
app.locals.authProviders.autoLoginProvider = (!app.locals.authProviders.ldap && !app.locals.authProviders.email && !app.locals.authProviders.openID && enabledExternalProviders.length === 1)
? enabledExternalProviders[0]
: null
// Export/Import menu items
app.locals.enableDropBoxSave = config.isDropboxEnable
app.locals.enableGitHubGist = config.isGitHubEnable