Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
Angular2 Firebase Set User Custom Propertise

I've been trying to set user custom properties or attributes using auth.updateProfile method but it only save displayName property because it's mentioned in its docs :

this.af.auth.createUser({
   email: formData.value.email,
   password: formData.value.password,
}).then((user) => {
   let userProfile = formData.value;
   userProfile.role = AuthService.ROLE_PATIENT;
   userProfile.displayName = `${formData.value.firstName} ${formData.value.lastName}`;
   user.auth.updateProfile(userProfile).then(function(){
   this.router.navigate(['/']);  
}); 

Now Problem how can i set custom properties of the user so i can get them in FirebaseAuthState

Question: Why i need to save custom properties with each user?

Answer: Because i'm working with Auth Guard to activate a particular route using role property which is saved in the database example:

canActivate(route: ActivatedRouteSnapshot,
              state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
    //Currently I'm using this which only check that user is logged in or not
    return this.auth
      .take(1)
      .map((authState: FirebaseAuthState) => !!authState)
      .do(authenticated => {
        if (!authenticated) this.router.navigate(['/login']);
      });   
  }

But i want one more check to validate the user has the role of patient which i've saved while creating the user above eg: return user.role == 'patient'

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The existing identity providers in Firebase Authentication have no way to add custom properties. If you want to add custom properties, you will either have to implement a custom identify provider (see minting custom tokens in a trusted process and signing in with a custom token) OR do a client-side look-up of the additional information from an alternate data source (such as the Firebase Database).

about 4 years ago · Santiago Trujillo Relatório

0

Perhaps you can do something like this:

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
    //Currently I'm using this which only check that user is logged in or not
    return this.auth
      .take(1)
      .map((authState: FirebaseAuthState) => {

        return this.af.database.list('/path/to/account').first().map((account: IAccount) => {

          if (authState && account.role === 'patient') {
            return true;
          }
          else {
            return this.router.navigate(['/login']);
          }
        });
      });
  }

It's quite far-fetched but it might just work. Or help you along the way to find an answer.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda