Skip to content

Instantly share code, notes, and snippets.

@cyan33
Last active July 18, 2017 14:08
Show Gist options
  • Save cyan33/525f3157fad65f94bf92e0d6a24af122 to your computer and use it in GitHub Desktop.
Save cyan33/525f3157fad65f94bf92e0d6a24af122 to your computer and use it in GitHub Desktop.
Use `localStorage` to Save Username and Pasword
// this assumes that you have jquery, or any ajax utils like `isomorphic-fetch`
function storeDataCb(username, password) {
if (!window.localStorage) return
localStorage.username = username
localStorage.password = password
}
function logIn() {
// check if the info has already been cached
if (localStorage.username && localStorage.password) {
// fill up the data using localStorage
}
}
$.ajax({
// url, body, etc
success: (data) => {
storeDataCb(data.username, data.password)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment