0

I'm trying to implement a role system with Firebase and at least I did it creating a collection into my database and comparing the actual uid vs the table (more or less).

But my question is if it's possible to set any property in the Firebase User object, like role: 'foo'. It's more a theoretical question.

Let's say that I create a user programmatically, like:

this.af.auth.createUser({ 'email': email, 'password': password })
    .then(createdUser => {
        ...
        createdUser['role'] = foo;
        ...... // How can I update the Firebase users database with this new user?
    })
    .catch(err => console.log(err));

I was watching around for some answer but nothing appears. Can anyone bring me some help?

Thanks!

1 Answer 1

1

The only secure way to add such roles to your user object is by using custom authentication, where you fully control the contents of the user JWT.

Most developers take an alternative route, where they store information about their users and roles in the Firebase Database and then secure data access through security rules. I recommend reading this blog post about implementing group security, and some of the results in this query.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.