@@ -2,7 +2,6 @@ import {Injectable} from '@angular/core';
22import { Subscription } from 'rxjs/Subscription' ;
33import { AngularFireDatabase , AngularFireObject } from '@angular/fire/database' ;
44import { AngularFireAuth } from '@angular/fire/auth' ;
5- import * as firebase from 'firebase/app' ;
65import { ActivatedRouteSnapshot , CanActivate , RouterStateSnapshot } from '@angular/router' ;
76import { GoogleAnalyticsService } from './google-analytics.service' ;
87import { FullStoryService } from './fullstory.service' ;
@@ -11,16 +10,17 @@ import {BehaviorSubject} from 'rxjs/BehaviorSubject';
1110import { Observable } from 'rxjs/Observable' ;
1211import { CodeConfirmationDialog } from './code-confirmation-dialog/code-confirmation.dialog' ;
1312import { MatDialog } from '@angular/material/dialog' ;
13+ import { auth , User as FirebaseUser } from 'firebase/app' ;
1414
1515@Injectable ( )
1616export class UsersService implements CanActivate {
1717 private adminSubscription : Subscription ;
1818 private userSubscription : Subscription ;
19- public authState : firebase . User ;
19+ public authState : FirebaseUser ;
2020 public isLoggedIn : boolean = false ;
2121 public isAdmin : boolean = false ;
2222 public currentUser : User ;
23- private userBehaviorSubject : BehaviorSubject < User > ;
23+ private readonly userBehaviorSubject : BehaviorSubject < User > ;
2424 public firebaseUserObservable : Observable < User > ;
2525 public firebaseUser : AngularFireObject < User > ;
2626
@@ -32,7 +32,7 @@ export class UsersService implements CanActivate {
3232 this . userBehaviorSubject = new BehaviorSubject ( null ) ;
3333 this . handleRedirect ( ) ;
3434
35- this . fbAuth . authState . subscribe ( ( authState : firebase . User ) => {
35+ this . fbAuth . authState . subscribe ( ( authState : FirebaseUser ) => {
3636 this . authState = authState ;
3737
3838 if ( authState ) {
@@ -60,7 +60,7 @@ export class UsersService implements CanActivate {
6060 login ( ) : void {
6161 this . gaService . sendEvent ( 'accounts' , 'login' ) ;
6262 if ( this . authState && this . authState . isAnonymous ) {
63- this . fbAuth . auth . currentUser . linkWithRedirect ( new firebase . auth . GoogleAuthProvider ( ) )
63+ this . fbAuth . auth . currentUser . linkWithRedirect ( new auth . GoogleAuthProvider ( ) )
6464 . catch ( ( error : any ) => {
6565 if ( error . credential ) {
6666 this . signInWithCredential ( error . credential ) ;
@@ -70,7 +70,7 @@ export class UsersService implements CanActivate {
7070 }
7171 } ) ;
7272 } else {
73- this . fbAuth . auth . signInWithRedirect ( new firebase . auth . GoogleAuthProvider ( ) )
73+ this . fbAuth . auth . signInWithRedirect ( new auth . GoogleAuthProvider ( ) )
7474 . catch ( ( error ) => {
7575 console . error ( `signInWithRedirect failed: ${ JSON . stringify ( error ) } ` ) ;
7676 this . gaService . sendEvent ( 'accounts' , 'signInWithRedirect_failure' ) ;
@@ -95,7 +95,7 @@ export class UsersService implements CanActivate {
9595 } ) ;
9696 }
9797
98- signInWithCredential ( credential : firebase . auth . AuthCredential ) : void {
98+ signInWithCredential ( credential : auth . AuthCredential ) : void {
9999 this . fbAuth . auth . signInWithCredential ( credential )
100100 . catch ( ( signInError ) => {
101101 console . error ( `signInWithCredential failed: ${ JSON . stringify ( signInError ) } ` ) ;
@@ -114,11 +114,11 @@ export class UsersService implements CanActivate {
114114 } ) ;
115115 }
116116
117- private setCurrentLoggedInUser ( authState : firebase . User ) {
117+ private setCurrentLoggedInUser ( authState : FirebaseUser ) {
118118 this . isLoggedIn = ! ! authState && ! authState . isAnonymous ;
119119 this . gaService . setUserId ( authState . uid ) ;
120120 this . fullStoryService . setUser ( authState . uid ,
121- authState . displayName || 'Anonymous' , authState . email || 'anonymous@marketamplified .com' ) ;
121+ authState . displayName || 'Anonymous' , authState . email || 'anonymous@devintent .com' ) ;
122122
123123 if ( ! authState . isAnonymous ) {
124124 this . firebaseUser = this . db . object < User > ( '/users/' + authState . uid ) ;
@@ -196,11 +196,7 @@ export class UsersService implements CanActivate {
196196 const isAdminObservable : Observable < any > = this . db . object ( '/admins/' + user . uid ) . valueChanges ( ) ;
197197 this . adminSubscription = isAdminObservable . subscribe (
198198 data => {
199- if ( data ) {
200- this . isAdmin = true ;
201- } else {
202- this . isAdmin = false ;
203- }
199+ this . isAdmin = ! ! data ;
204200 } ,
205201 err => {
206202 console . error ( 'Failed to read from ' + '/admins/' + user . uid + ': ' + err ) ;
0 commit comments