угловая 8 наблюдаемая пожарная база, асинхронная труба - PullRequest
0 голосов
/ 10 июля 2019

У меня есть такая служба аутентификации

authState$: BehaviorSubject < any > ;

constructor(
    private af: AngularFireAuth,
    private db: AngularFirestore,
    public router: Router) {
    this.authState$ = new BehaviorSubject < any > ({});
}

doMicorosftLogin() {
    this.authState$.next(Object.assign({}, {
        uid: null,
        loading: true
    }));
    const provider = new
    auth.OAuthProvider('microsoft.com').setCustomParameters({
        tenant: 'aaa-bbb-ccc-ddd'
    });
    this.af.auth
        .setPersistence(auth.Auth.Persistence.LOCAL).then(() => {
            this.af.auth.signInWithPopup(provider)
                .then(res => {
                    this.authState$.next(Object.assign({}, {
                        uid: res.user.uid,
                        loading: false
                    }));
                }, err => {
                    console.log(err);
                });
        });
}

, и мой компонент входа в систему такой:

constructor(
  public authService: AuthService
) {
  this.auth$ = this.authService.authState$;
}

<div *ngIf="auth$ | async as user">
  -{{user | json}}-
</div>

Итак, когда я вызываю

authService.doMicorosftLogin ()

загрузка установлена ​​на "true", но не изменяется после успешного входа в систему, но если я повторяю (без перезагрузки страницы), это работает.

Шаги

вызов doMicorosftLogin ()

loading = true

успешный вход в систему -> ничего не происходит

отзыв doMicorosftLogin ()

загрузка= true

успешный вход в систему -> загрузка = false

...