I am facing an issue with my Angular Application where I cannot change the email of a logged-in authenticated user in Firebase.
Fetching the email as an observable works fine:
getUserEmail():Observable<string | null>{
return this.afAuth.authState.pipe(map(user => user? user.email : null));
}
However, when attempting to update the user's email, it only returns an observable:
updateUserEmail(newEmail: string){
return this.afAuth.authState.pipe(map(user => user? user.updateEmail(newEmail) : null));
}
Below are the relevant parts of the service:
import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
import { Router } from '@angular/router';
import { from, Observable, Subject } from 'rxjs';
import { map } from "rxjs/operators";
import { UIService } from '../shared/ui.service';
import { AuthData } from "./auth-data.model";
import { UserData } from './user-data.model';
import { User } from "./user.model";
import { UserService } from './user.service';
@Injectable()
export class AuthService {
public authChange = new Subject<boolean>();
private isAuthenticated: boolean = false;
public userLoggedIn: User | null = null;
public userUID$: Observable<string>;
public auth: any;
constructor(private router: Router,
private afAuth: AngularFireAuth,
private uiService: UIService,
private user: UserService)
{
this.userUID$ = afAuth.authState.pipe(map(user => user? user.uid : null));
}
getUserEmail():Observable<string | null>{
return this.afAuth.authState.pipe(map(user => user? user.email : null));
}
updateUserEmail(newEmail: string, password:string, oldEmail:string){
return this.afAuth.authState.pipe(map(user => user? user.updateEmail(newEmail) : null));
}
}