From d9a6ae74f336eccee5bab05b648a4f80f3563105 Mon Sep 17 00:00:00 2001 From: Jeff Cross Date: Tue, 21 Jun 2016 00:05:18 -0700 Subject: [PATCH] fix(auth): make sure onAuth runs in Angular zone There is one place in auth that takes a promise from Firebase, the promise from getRedirectResult(), and creates an observable from it. Since Firebase is using their own Promise implementation, the Promise and its derived observable were running in the root zone instead of the Angular zone, causing onAuth changes to not immediately be propagated to the view. By casting the firebase Promise to a zone-patched Promise, the observable now runs in the Angular zone. Fixes #231 --- src/providers/firebase_sdk_auth_backend.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/providers/firebase_sdk_auth_backend.ts b/src/providers/firebase_sdk_auth_backend.ts index 0c97ef1df..9c4ce0bcc 100644 --- a/src/providers/firebase_sdk_auth_backend.ts +++ b/src/providers/firebase_sdk_auth_backend.ts @@ -33,7 +33,7 @@ export class FirebaseSdkAuthBackend extends AuthBackend { } createUser(creds: EmailPasswordCredentials): Promise { - return >this._fbAuth.createUserWithEmailAndPassword(creds.email, creds.password) + return Promise.resolve(this._fbAuth.createUserWithEmailAndPassword(creds.email, creds.password)) .then((user: firebase.User) => authDataToAuthState(user)); } @@ -53,21 +53,21 @@ export class FirebaseSdkAuthBackend extends AuthBackend { } unauth(): void { - this._fbAuth.signOut(); + Promise.resolve(this._fbAuth.signOut()); } authWithCustomToken(token: string): Promise { - return >this._fbAuth.signInWithCustomToken(token) + return Promise.resolve(this._fbAuth.signInWithCustomToken(token)) .then((user: firebase.User) => authDataToAuthState(user)); } authAnonymously(): Promise { - return >this._fbAuth.signInAnonymously() + return Promise.resolve(this._fbAuth.signInAnonymously()) .then((user: firebase.User) => authDataToAuthState(user)); } authWithPassword(creds: EmailPasswordCredentials): Promise { - return >this._fbAuth.signInWithEmailAndPassword(creds.email, creds.password) + return Promise.resolve(this._fbAuth.signInWithEmailAndPassword(creds.email, creds.password)) .then((user: firebase.User) => authDataToAuthState(user)); } @@ -76,7 +76,7 @@ export class FirebaseSdkAuthBackend extends AuthBackend { if (options.scope) { options.scope.forEach(scope => providerFromFirebase.addScope(scope)); } - return >this._fbAuth.signInWithPopup(providerFromFirebase); + return Promise.resolve(this._fbAuth.signInWithPopup(providerFromFirebase)); } /** @@ -85,16 +85,16 @@ export class FirebaseSdkAuthBackend extends AuthBackend { * You should subscribe to the FirebaseAuth object to listen succesful login */ authWithOAuthRedirect(provider: AuthProviders, options?: any): Promise { - return >this._fbAuth.signInWithRedirect(this._enumToAuthProvider(provider)); + return Promise.resolve(this._fbAuth.signInWithRedirect(this._enumToAuthProvider(provider))); } authWithOAuthToken(credential: firebase.auth.AuthCredential): Promise { - return >this._fbAuth.signInWithCredential(credential) + return Promise.resolve(this._fbAuth.signInWithCredential(credential)) .then((user: firebase.User) => authDataToAuthState(user)); } getRedirectResult(): Observable { - return Observable.fromPromise(>this._fbAuth.getRedirectResult()); + return Observable.fromPromise(Promise.resolve(this._fbAuth.getRedirectResult())); } private _enumToAuthProvider(providerId: AuthProviders): firebase.auth.AuthProvider | FirebaseOAuthProvider {