Skip to content

Commit 6b14c4f

Browse files
committed
Improving preventDefault implementation
* Ensuring form submission is handled on non credentials enabled browsers.
1 parent d2f0436 commit 6b14c4f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

demos/credential-management/script.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,12 @@ document.querySelector('#signout').addEventListener('click', function () {
8181
*/
8282
function handleFederation(e) {
8383
console.log("Signed in via a federation!");
84-
e.preventDefault();
8584

8685
if (navigator.credentials) {
86+
// Stop the default form submission.
87+
e.preventDefault();
88+
89+
// In a real environment extract the credentials from the federated credential response.
8790
var c = new FederatedCredential({
8891
8992
provider: 'https://accounts.federation.com/',
@@ -107,9 +110,13 @@ function handleFederation(e) {
107110
*/
108111
document.querySelector('form').addEventListener('submit', function (e) {
109112
console.log("Submitted a sign-in form.");
110-
e.preventDefault();
111113

112114
if (navigator.credentials) {
115+
// Stop the default form submission.
116+
e.preventDefault();
117+
118+
// In a real site, we'd check the credentials are valid
119+
113120
var c = new PasswordCredential({
114121
id: document.querySelector('#username').value,
115122
password: document.querySelector('#password').value,

0 commit comments

Comments
 (0)