Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- constructor(@Inject(AuthenticationService) private authSvc: AuthenticationService){
- this.authSvc.getAuthChangeObservable().subscribe(data => this.onAuthenticationChanged(data) );
- }
- private authChange: Observable<any>;
- private _authObserver: Observer<any>;
- constructor(@Inject(FirebaseService) firebaseService: FirebaseService){
- // Cookies or whatever allow .auth() to identify the user after a page refresh
- // This causes a slight delay, see my question below
- firebase.auth().onAuthStateChanged(user => {
- if(user) this.onAuthenticationSuccessfull(user);
- else this.onLogoutSuccessfull();
- });
- // Create an observable for auth status
- this.authChange = new Observable(observer => {
- this._authObserver = observer;
- }).share();
- }
- getAuthChangeObservable(){
- return this.authChange;
- }
- ...
- onAuthenticationSuccessfull(user){
- this.authenticatedUser = user;
- // This is mainly the way I found to warn other services they are clear to load the
- // user-related data
- this._authObserver.next('auth');
- }
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement