Last active
July 18, 2017 14:08
-
-
Save cyan33/525f3157fad65f94bf92e0d6a24af122 to your computer and use it in GitHub Desktop.
Use `localStorage` to Save Username and Pasword
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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