mirror of
https://github.com/zitadel/zitadel.git
synced 2025-05-06 09:16:49 +00:00
fix(login): passkey setup when pressing "Enter" key on login form (#9485)
# Which Problems Are Solved When registering passkeys or u2f methods as second factor, some users pressed the "Enter" key, rather than clicking the submit button. This method has bypassed the execution of the device registration and encoding scripts, resulting in the form being submitted without the necessary encoded values. # How the Problems Are Solved This PR ensures that device registration is always executed and the required information are submitted in the form regardless of pressing "Enter" or clicking the button. # Additional Changes None # Additional Context - closes #6592 - closes #2910
This commit is contained in:
parent
92f0cf018f
commit
27b319bd98
@ -1,4 +1,4 @@
|
|||||||
function checkWebauthnSupported(button, func) {
|
function checkWebauthnSupported(func, optionalClickId) {
|
||||||
let support = document.getElementsByClassName("wa-support");
|
let support = document.getElementsByClassName("wa-support");
|
||||||
let noSupport = document.getElementsByClassName("wa-no-support");
|
let noSupport = document.getElementsByClassName("wa-no-support");
|
||||||
if (!window.PublicKeyCredential) {
|
if (!window.PublicKeyCredential) {
|
||||||
@ -10,7 +10,13 @@ function checkWebauthnSupported(button, func) {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
document.getElementById(button).addEventListener("click", func);
|
|
||||||
|
// if id is provided add click event only, otherwise call the function directly
|
||||||
|
if (optionalClickId) {
|
||||||
|
document.getElementById(optionalClickId).addEventListener("click", func);
|
||||||
|
} else {
|
||||||
|
func();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function webauthnError(error) {
|
function webauthnError(error) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
"DOMContentLoaded",
|
"DOMContentLoaded",
|
||||||
checkWebauthnSupported("btn-login", login)
|
checkWebauthnSupported(login, "btn-login"),
|
||||||
);
|
);
|
||||||
|
|
||||||
async function login() {
|
async function login() {
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
"DOMContentLoaded",
|
"DOMContentLoaded",
|
||||||
checkWebauthnSupported("btn-register", registerCredential)
|
() => {
|
||||||
|
const form = document.getElementsByTagName("form")[0];
|
||||||
|
if (form) {
|
||||||
|
form.addEventListener("submit", (event) => {
|
||||||
|
event.preventDefault(); // Prevent the default form submission
|
||||||
|
checkWebauthnSupported(registerCredential);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
async function registerCredential() {
|
async function registerCredential() {
|
||||||
@ -8,7 +16,7 @@ async function registerCredential() {
|
|||||||
|
|
||||||
let opt;
|
let opt;
|
||||||
try {
|
try {
|
||||||
opt = JSON.parse(atob(document.getElementsByName("credentialCreationData")[0].value));
|
opt = JSON.parse(window.atob(document.getElementsByName("credentialCreationData")[0].value));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
webauthnError({ message: "Failed to parse credential creation data." });
|
webauthnError({ message: "Failed to parse credential creation data." });
|
||||||
return;
|
return;
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
</a>
|
</a>
|
||||||
|
|
||||||
<span class="fill-space"></span>
|
<span class="fill-space"></span>
|
||||||
<a id="btn-register" class="lgn-raised-button lgn-primary wa-support">{{t "InitMFAU2F.RegisterTokenButtonText"}}</a>
|
<button type="submit" id="btn-register" class="lgn-raised-button lgn-primary wa-support">{{t "InitMFAU2F.RegisterTokenButtonText"}}</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
<div class="lgn-actions">
|
<div class="lgn-actions">
|
||||||
<span class="fill-space"></span>
|
<span class="fill-space"></span>
|
||||||
{{if not .Disabled}}
|
{{if not .Disabled}}
|
||||||
<a id="btn-register" class="lgn-raised-button lgn-primary wa-support">{{t "PasswordlessRegistration.RegisterTokenButtonText"}}</a>
|
<button type="submit" id="btn-register" class="lgn-raised-button lgn-primary wa-support">{{t "PasswordlessRegistration.RegisterTokenButtonText"}}</button>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user