1

I was wondering if this is possible using Firebase and React.

I want to create a admin panel where the admins can add new user and assign roles. The moderators should also be able to login and make a new post (the new post part i have figured out).

However i dont want any users to be able to register on their own, just the admin to add them to the site.

Is this possible and in that case, how? Grateful for input and thoughts

crushen
  • 78
  • 10
  • Yes, Firebase can do this. But. Firebase has not concept of 'Admin' users - all users are just users so if you want an 'admin' user to have special ability, you have to code you app for that. Also keep in mind that in some situations, when a logged in user 'creates' another user, it will log that user our and log the newly created use in. You should do some research before getting too far long. – Jay Sep 18 '19 at 17:20
  • Thank you for taking time to answer. Yes and Im trying to create a firebase collection named users and every document should have the user ID that Firebaseapp creates as a name. I also thought that i could use the basic signup form that i have and restrict it to the admin. But i noticed that i automatically gets signed in, as you mentioned. Do you know what the best aproach to user management is? To create new users, shown them as a list,deleting and so on. I know there is a thing called admin sdk but as i understand it i should not use it on a webbserver? – crushen Sep 19 '19 at 06:37

1 Answers1

0

Yes its possible, just create and Interface which is able to send data to firebase. Here you have a little example. I've just create and APP which connects to firebase. Firebase saves a lot of time becase you dont have to control the Auth and the Users SingUp, it has functions to do it.

I will sugest you to use it with ReactForm (to send the data) abd the ReactRedux to control states and the LogIn, LogOut and SignUp.

https://medium.com/firebase-developers/how-to-setup-firebase-authentication-with-react-in-5-minutes-maybe-10-bb8bb53e8834

Fore more info check Google Documentation. https://firebase.google.com/docs/auth

P4uB0rd4
  • 175
  • 5
  • Hi, thanks for the answer. I actually have a user authentication system in play already. But the important thing for me is that only me as an administrator should be able to add users. But i just have a hard time getting my head around how it should be done. A bit similar to how Wordpress does it. – crushen Sep 18 '19 at 09:31
  • First add firebase`firebase.initializeApp({ apiKey: "yourkeyhere", ....... });`So `firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) { // Handle Errors here. var errorCode = error.code; var errorMessage = error.message; // ... });` you can add a user, you can call this after a validation in a form and also you can create in firebase a DB to store users too with `Database.child("users").child(userId).child("username").setValue(name);` @crushen – P4uB0rd4 Sep 18 '19 at 09:43
  • Somthing similar to this then: `createUser = (e) => { e.preventDefault() firebase.auth().createUserWithEmailAndPassword(this.state.email, this.state.password) .then(cred => { const db = firebase.firestore(); return db.collection('users').doc(cred.uid.id).set({ company: this.state.company, email: this.state.email, }) })` The user register works but not the additional info tho. Thanks for taking the time to answer – crushen Sep 18 '19 at 10:32
  • Yes, you create user and then you add the data into the Firebase storage. I suggest you to have it in different files, have the "front-end" with views in one and call this function which is declared in other file (just saying this because i see the this.state.email and this.state.company). There is ReactRedux extension which can help you to do this with differents dispatchs. Be carefull with the path to `db.collection('users').doc(cred.uid.id).`because if it isnt set properly it wont work. I recommend you to use `Database.child("users").child(userId). child("username")` @crushen – P4uB0rd4 Sep 18 '19 at 10:36