Created
January 10, 2012 06:22
-
-
Save naholyr/1587384 to your computer and use it in GitHub Desktop.
[snippet] implement "remember me" with BrowserId
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
| // https://github.com/mozilla/browserid/wiki/Advanced-BrowserID-Features | |
| function login () { | |
| function gotAssertion (assertion) { | |
| if (assertion) { | |
| // User chose not to log in, or an error occurred | |
| } else { | |
| // Ajax call to server to check email | |
| } | |
| } | |
| // Retrieve previous session | |
| navigator.id.get(function (assertion) { | |
| if (assertion) { | |
| // Got one! | |
| gotAssertion(assertion); | |
| } else { | |
| // Need to log in for the first time | |
| navigator.id.get(gotAssertion, {allowPersistent: true}); | |
| } | |
| }, {silent: true}); | |
| } | |
| function logout() { | |
| navigator.id.logout(function (ok) { | |
| // ok if the user is properly logged out | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment