Files
wekan/client/lib/authenticationSubmit.js
T
Lauri Ojansivu b4459a79e2 Fix duplicate LDAP form submissions and display login failures
Capture sign-in submission before asynchronous provider selection, keep the form mounted, and complete only the chosen login path. Preserve password validation and show provider errors without redirecting.

Thanks to Nissulya and xet7 !

Fixes #6692,
2026-09-23 13:18:29 +03:00

41 lines
1.4 KiB
JavaScript

// Capture submission before the nested accounts form can start a password login.
// Keep that form mounted while resolving the selected authentication method.
function createAuthenticationSubmitHandler({
isSignIn, readCredentials, resolveMethod, submitPassword, login, complete, setBusy,
}) {
let pending = false;
let replayingPassword = false;
return async function submit(event) {
if (event.target.id !== 'at-pwd-form' || !isSignIn() || replayingPassword) return;
event.preventDefault();
event.stopImmediatePropagation();
if (pending) return;
const form = event.target;
const { username, password } = readCredentials(form);
pending = true;
try {
setBusy(true);
const method = username && password ? await resolveMethod(username) : 'password';
if (!['ldap', 'saml', 'cas'].includes(method)) {
// Let useraccounts retain its validation, normalization and 2FA flow.
setBusy(false);
replayingPassword = true;
try { submitPassword(form); } finally { replayingPassword = false; }
return;
}
await new Promise((resolve, reject) => {
login(method, username, password, error => error ? reject(error) : resolve());
});
setBusy(false);
complete();
} catch (error) {
setBusy(false);
complete(error);
} finally {
pending = false;
}
};
}
module.exports = { createAuthenticationSubmitHandler };