I am trying to set user properties or user attributes using the auth.updateProfile method, but it only saves the displayName property because it is mentioned in 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 the problem is how to set user properties for the user so that I can get them in FirebaseAuthState
Question: Why do I need to save custom properties with each user?
Answer: Because I am working with Auth Guard to activate a specific route using the role property, which is saved in the sample database:
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
But I want one more check to verify that the user has a patient role that I saved when creating the user above, for example: return user.role == 'patient'
source share