Skip to content

Instantly share code, notes, and snippets.

@mikewest
Created April 15, 2016 12:28
Show Gist options
  • Save mikewest/c36844c5310f5307cb7c7c71e14864d7 to your computer and use it in GitHub Desktop.
Save mikewest/c36844c5310f5307cb7c7c71e14864d7 to your computer and use it in GitHub Desktop.
Eventbrite
//
// On https://www.eventbrite.com/
//
// First, adjust the `autocomplete` attributes on the email and password form fields:
document.querySelector('#login-email').setAttribute('autocomplete', 'username');
document.querySelector('#login-password').setAttribute('autocomplete', 'current-password');
// Then hook up an event listener to the form to catch typed/autofilled sign-ins:
//
// On the real site, they'd hook this up to the dispatcher that kicks off an XHR to login/:
document.querySelector('.responsive-form.l-mar-top-3').addEventListener('submit', e => {
if (navigator.credentials) {
e.preventDefault();
var c = new PasswordCredential(e.target);
fetch(e.target.action, { credentials: c, method: 'POST' })
.then(r => {
if (r.type == 'opaqueredirect') { // If we're redirected, success! (Ideally, this could be more explicit)
navigator.credentials.store(c).then(_ => {
window.location = "http://www.eventbrite.com/[exciting_landing_page_goes_here]";
});
} else {
// Do something clever to handle the sign-in error.
}
});
}
});
// And then try to grab credentials:
navigator.credentials.get({
password: true,
/*
Adding `, unmediated: true` here would grab credentials automatically if
they've allowed that access, and would just return `undefined` without
asking the user if they haven't.
*/
})
.then(c => {
if (c instanceof PasswordCredential) {
c.additionalData = new FormData(document.querySelector('.responsive-form.l-mar-top-3'));
c.idName = "email";
fetch("/login", { credentials: c, method: 'POST' })
.then(r => {
if (r.type == 'opaqueredirect') { // If we're redirected, success!
navigator.credentials.store(c).then(_ => {
window.location = "http://www.eventbrite.com/[exciting_landing_page_goes_here]";
});
} else {
// Do something clever to handle the sign-in error.
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment