Skip to content

Instantly share code, notes, and snippets.

@thangman22
Created January 29, 2017 05:56
Show Gist options
  • Save thangman22/8c5342c883afe022f9f03b160847c707 to your computer and use it in GitHub Desktop.
Save thangman22/8c5342c883afe022f9f03b160847c707 to your computer and use it in GitHub Desktop.
navigator.credentials.get({
password: true
}).then(function(cred) {
console.log(cred)
if(cred){
$("#status").append("<li>Login Credential Found</li>")
fetch('login.php', {
method: 'POST',
credentials: cred
}).then(function(res) {
return res.text();
}).then((text) => {
$("#status").append("<li>Auto Login [" + cred.id + "] Complete</li>")
})
}
})
document.querySelector('#loginForm').addEventListener("submit", e => {
e.preventDefault();
if (navigator.credentials) {
console.log(e.target)
let form = document.querySelector('#loginForm')
let c = new PasswordCredential(e.target)
navigator.credentials.store(c)
fetch('login.php', {
method: 'POST',
credentials: c
}).then(function(res) {
return res.text();
}).then((text) => {
$("#status").append("<li>Login Complete</li>")
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment