mirror of
https://github.com/wekan/wekan.git
synced 2026-11-26 14:45:11 -05:00
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,
41 lines
1.4 KiB
JavaScript
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 };
|