Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving preventDefault implementation #509

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions demos/credential-management/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ document.querySelector('#signout').addEventListener('click', function () {
*/
function handleFederation(e) {
console.log("Signed in via a federation!");
e.preventDefault();

if (navigator.credentials) {
// Stop the default form submission.
e.preventDefault();

// In a real environment extract the credentials from the federated credential response.
var c = new FederatedCredential({
id: '[email protected]',
provider: 'https://accounts.federation.com/',
Expand All @@ -107,9 +110,13 @@ function handleFederation(e) {
*/
document.querySelector('form').addEventListener('submit', function (e) {
console.log("Submitted a sign-in form.");
e.preventDefault();

if (navigator.credentials) {
// Stop the default form submission.
e.preventDefault();

// In a real site, we'd check the credentials are valid

var c = new PasswordCredential({
id: document.querySelector('#username').value,
password: document.querySelector('#password').value,
Expand Down