Nano
Nano

Reputation: 847

Add keys to Firebase user Object using AngularFire2

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!

Upvotes: 0

Views: 78

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598857

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.

Upvotes: 1

Related Questions