FirebaseExtended / firechat

Real-time Chat powered by Firebase
https://firechat.firebaseapp.com
MIT License
2.41k stars 1.04k forks source link

How to give a user moderator role #84

Open shreyasingh25 opened 7 years ago

shreyasingh25 commented 7 years ago

How do we make users as moderators. I have tried adding a record with :true under /moderators in my Firebase console, but it isn't registering that user as moderator. Is there any other way of doing this? Or Am I missing something screen shot 2017-03-29 at 2 54 00 pm

katowulf commented 7 years ago

Well, I can see that moderators are implemented, and that admin functions are bound to the UI here, so can you provide a minimal repro showing what you mean by "not registering"? That could mean just about anything, really.

Note that you do need to make sure you have security rules in place to enforce moderator privs.

shreyasingh25 commented 7 years ago

What I meant by not registering is that the user doesnt get the moderator privileges. I have noticed that when i refresh the chat, a few fields get highlighted in the realtime database, like the user, room-metadata and user-names-online, but moderators doesn't. This made me wonder if I had set the moderator in the right manner.

About the security rules, I did add for moderator - screen shot 2017-03-30 at 9 50 01 am

Do i need to add these in some other place as well?

katowulf commented 7 years ago

Seems like you've done it correctly, from my limited expertise. Got a minimal repro you can share?

shreyasingh25 commented 7 years ago

This is all I have in place -

var config = { config from firebase console here! };

firebase.initializeApp(config);

function login() { // Log the user in via google var provider = new firebase.auth.GoogleAuthProvider(); firebase.auth().signInWithPopup(provider).catch(function (error) { console.log("Error authenticating user:", error); }); }

firebase.auth().onAuthStateChanged(function (user) { // Once authenticated, instantiate Firechat with the logged in user if (user) { initChat(user); } });

function initChat(user) { // Get a Firebase Database ref var chatRef = firebase.database().ref("chat");

// Create a Firechat instance
var chat = new FirechatUI(chatRef, document.getElementById("firechatWrapper"));

// Set the Firechat user
// user.isModerator = true;
chat.setUser(user.uid, user.displayName);

}

alecube commented 3 years ago

Hi! it's been a long time but did you make it work? I'm having the same problem.

Thanks

caohanh1502 commented 3 years ago

Hi! it's been a long time but did you make it work? I'm having the same problem.

Thanks

Somehow I did make it work, but idk why. I think I add one more user as moderator and it works (maybe it's because of the firebase itselft). Also don't forget to include firebase-ui.js image