-
-
Save vishalforcode/48a5e67ddac90dbdd22a6a4b099cc072 to your computer and use it in GitHub Desktop.
Role-based security in Firebase
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 shows how you can authenticate users and store user data in Firebase | |
| using Firebase Simple Login with Twitter. The corresponding security rules for | |
| this app are available in this gist: https://gist.github.com/sararob/8694d5b4111e4ed31cec */ | |
| // Define Firebase references | |
| var ref = new Firebase("<your-firebase>.firebaseio.com/"); | |
| var usersRef = ref.child("users"); | |
| // Call an 'auth' function when a user clicks a login button (this example uses twitter) | |
| $('#login').on("click", function () { | |
| auth.login('twitter'); | |
| }); | |
| // Authenticate users and store each user in Firebase by their Twitter UID | |
| var auth = new FirebaseSimpleLogin(ref, function (error, user) { | |
| if (error) { | |
| console.log(error); | |
| } else if (user) { | |
| usersRef.child(user.uid).set({pic: user.thirdPartyUserData.profile_image_url, username: user.username}); | |
| } else { | |
| //user is logged out | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment