I'm either missing something obvious or doing something stupid but I can't figure out how to do this.
I'm subscribing to AngularFireAuth authState in a service handling the current user. This works fine and the subscription is retriggered after logging out and logging in again (I see the console output twice):
export class TestCurrentUserService {
constructor( private afAuth: AngularFireAuth) { }
getCurrentUser() :Observable<any> {
return this.afAuth.authState.pipe(
switchMap(user => {
console.log("I have a user")
return of(user)
})
)
}
updateUser() {
var user = firebase.auth().currentUser;
user.updateProfile({
displayName: "Mickey Mouse",
});
}
}
The getCurrentUser() function is subscribed to in a number of places in the code and the userProfile data is used from the returned user.
The service also has a function to update the user profile. This also works but I'm expecting that with a change to the user account the authState subscription would be retriggered. I want the user profile changes to propagate through the application without the need to logout and log in again.
More in hope than expectation, I've tried manually retriggering the authState with a method that works fine for http calls but to no effect:
export class TestCurrentUserService {
constructor( private afAuth: AngularFireAuth) { }
triggerer = new Subject<any>();
getCurrentUser() :Observable<any> {
return this.afAuth.authState.pipe(
repeatWhen(() => this.triggerer),
switchMap(user => {
console.log("I have a user")
return of(user)
})
)
}
refreshUser() {
this.triggerer.next()
}
}
So, am I going about this the wrong way? How would I go about propagating the changes I've made to the user profile through my app?
Many thanks.
question from:
https://stackoverflow.com/questions/65874670/how-to-retrigger-angularfireauth-subscription-after-calling-updateprofile 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…