Last active
April 26, 2022 22:21
-
Star
(142)
You must be signed in to star a gist -
Fork
(25)
You must be signed in to fork a gist
-
-
Save sararob/331760829a9dcb4be3e7 to your computer and use it in GitHub Desktop.
Revisions
-
sararob revised this gist
Dec 23, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ "$room": { "$message": { //can add a message if they are a MEMBER ".write": "(!data.exists() && newData.exists() && root.child('rooms/' + $room + '/users/' + auth.uid).val() >= 10)" } } } -
sararob revised this gist
Sep 5, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ /* This example shows how you can use your data structure as a basis for your Firebase security rules to implement role-based security. We store each user by their Twitter uid, and use the following simplistic approach for user roles: -
sararob revised this gist
Sep 5, 2014 . 2 changed files with 17 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -44,16 +44,19 @@ shows the corresponding security rules. ... }, "messages": { "public-room-1": { -JVwTPcWMIt0J6Gbtrqh: { "user": "twitter:12345", "text": "Hello everyone!" } ... }, "admin-only-room": { -JVwU5tLQRPbzXo4s_a1: { "user": "twitter:56789", "text": "This is a top secret message." } ... } } } 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 charactersOriginal file line number Diff line number Diff line change @@ -18,9 +18,11 @@ } }, "messages": { "$room": { "$message": { //can add a message if they are a MEMBER ".write": "(!data.exists() && newData.exists() && root.child($room + '/users/' + auth.uid).val() >= 10)" } } } } -
sararob revised this gist
Sep 4, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ "messages": { "$message": { //can add a message if they are a MEMBER ".write": "(!data.exists() && newData.exists() && root.child('/rooms/' + $room + '/users/' + auth.uid).val() >= 10)" } } } -
sararob revised this gist
Sep 4, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -40,7 +40,8 @@ shows the corresponding security rules. "users": { "twitter:56789": 20 } } ... }, "messages": { -JVwTPcWMIt0J6Gbtrqh: { @@ -53,5 +54,6 @@ shows the corresponding security rules. "user": "twitter:56789", "text": "This is a top secret message." } ... } } -
sararob revised this gist
Sep 4, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,8 @@ for user roles: 20 - MODERATOR 99 - ADMINISTRATOR This file shows the data structure, and the security-rules file below shows the corresponding security rules. */ -
sararob revised this gist
Sep 4, 2014 . 3 changed files with 8 additions and 45 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,8 @@ for user roles: 20 - MODERATOR 99 - ADMINISTRATOR This file shows the data structure, and the security-rules file below shows the corresponding security rules. */ { 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 charactersOriginal file line number Diff line number Diff line change @@ -1,39 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,6 @@ { "rules": { ".read": true, "users": { "$user": { //can add a message if authenticated @@ -22,6 +16,12 @@ } } } }, "messages": { "$message": { //can add a message if they are a MEMBER ".write": "(!data.exists() && newData.exists() && root.child($room + '/users/' + auth.uid).val() >= 10)" } } } } -
sararob revised this gist
Sep 4, 2014 . 3 changed files with 81 additions and 16 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ /* This example shows how you can used your data structure as a basis for your Firebase security rules to implement role-based security. We store each user by their Twitter uid, and use the following simplistic approach for user roles: 0 - GUEST 10 - USER 20 - MODERATOR 99 - ADMINISTRATOR */ { "users": { "twitter:12345": { "full-name": "Sara Robinson", "username": "SRobTweets", "role-value": 10 }, "twitter:56789": { "full-name": "Michael 'Kato' Wulf", "username": "katowulf", "role-value": 20 } .... }, "rooms": { "public-room-1": { "users": { "twitter:56789": 20, "twitter:12345": 10 } }, "admin-only-room": { "users": { "twitter:56789": 20 } }, }, "messages": { -JVwTPcWMIt0J6Gbtrqh: { "room-id": "public-room-1", "user": "twitter:12345", "text": "Hello everyone!" }, -JVwU5tLQRPbzXo4s_a1: { "room-id": "admin-only-room", "user": "twitter:56789", "text": "This is a top secret message." } } } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ { "rules": { ".read": true, "messages": { "$message": { //can add a message if they are a MEMBER ".write": "(!data.exists() && newData.exists() && root.child($room + '/users/' + auth.uid).val() >= 10)" } }, "users": { "$user": { //can add a message if authenticated ".write": "auth.uid === $user" } }, "rooms": { "$room": { "users": { // can write to the users list only if ADMINISTRATOR "$user": { "write":"newData.parent().child(auth.uid).val() === 99" } } } } } } 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 charactersOriginal file line number Diff line number Diff line change @@ -1,16 +0,0 @@ -
sararob revised this gist
Sep 2, 2014 . 2 changed files with 18 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ /* This shows how you can authenticate users and store user data in Firebase using Firebase Simple Login with Twitter. The corresponding security rules are in the security.json file */ // Define Firebase references var ref = new Firebase("<your-firebase>.firebaseio.com/"); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ { "rules": { ".read": true, "messages": { "$message": { ".write": "auth.uid != null && auth.uid === newData.child('user').val()", ".validate": "newData.child('message').val() != ''" } }, "users": { "$user": { ".write": "auth.uid === $user" } } } } -
sararob revised this gist
Sep 2, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -34,6 +34,6 @@ $('#message-submit').on('click', function () { messagesRef.push({user: currentUser.uid, username: currentUser.username, message: message}); } else { alert('You must login with Twitter to post!'); } }); -
sararob revised this gist
Sep 2, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -30,9 +30,9 @@ $('#message-submit').on('click', function () { var message = $('#msgInput').val(); //Send the message to Firebase messagesRef.push({user: currentUser.uid, username: currentUser.username, message: message}); } else { alert('You must login with Twitter to post!'); } -
sararob revised this gist
Sep 2, 2014 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -27,11 +27,12 @@ var auth = new FirebaseSimpleLogin(ref, function (error, user) { // When a user adds a message, add the message data to Firebase $('#message-submit').on('click', function () { if (currentUser != null) { var message = $('#msgInput').val(); //Send the message to Firebase messagesRef.push({user: currentUser.uid, username: currentUser.username, message: message}); } else { alert('You must login with Twitter to post!'); } -
sararob revised this gist
Sep 2, 2014 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -27,12 +27,12 @@ var auth = new FirebaseSimpleLogin(ref, function (error, user) { // When a user adds a message, add the message data to Firebase $('#message-submit').on('click', function () { if (currentUser != null) { var message = $('#msgInput').val(); //Send the message to Firebase messagesRef.push({user: currentUser.uid, username: currentUser.username, message: message}); } else { alert('You must login with Twitter to post!'); } }); -
sararob revised this gist
Sep 2, 2014 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -26,12 +26,13 @@ var auth = new FirebaseSimpleLogin(ref, function (error, user) { // When a user adds a message, add the message data to Firebase $('#message-submit').on('click', function () { if (currentUser != null) { var message = $('#msgInput').val(); //Send the message to Firebase messagesRef.push({user: currentUser.uid, username: currentUser.username, message: message}); } else { alert('You must login with Twitter to post!'); } }); -
sararob revised this gist
Sep 2, 2014 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,7 @@ this app are available in this gist: https://gist.github.com/sararob/8694d5b4111 // Define Firebase references var ref = new Firebase("<your-firebase>.firebaseio.com/"); var usersRef = ref.child("users"); var currentUser = null; //we'll use this to see if a user is currently logged in // Call an 'auth' function when a user clicks a login button (this example uses twitter) $('#login').on("click", function () { @@ -17,7 +18,20 @@ var auth = new FirebaseSimpleLogin(ref, function (error, user) { console.log(error); } else if (user) { usersRef.child(user.uid).set({pic: user.thirdPartyUserData.profile_image_url, username: user.username}); currentUser = user; } else { //user is logged out } }); // When a user adds a message, add the message data to Firebase $('#message-submit').on('click', function () { if (currentUser != null) { var message = $('#msgInput').val(); //Send the message to Firebase messagesRef.push({user: currentUser.uid, username: currentUser.username, message: message}); } else { alert('You must login with Twitter to post!'); } }); -
sararob revised this gist
Sep 2, 2014 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ /* 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"); @@ -10,7 +14,7 @@ $('#login').on("click", function () { // 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 { -
sararob revised this gist
Sep 2, 2014 . 1 changed file with 10 additions and 11 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,19 @@ // 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 } }); -
sararob renamed this gist
Sep 2, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
sararob created this gist
Sep 2, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ // 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 { } });