Skip to content

Commit 981f0f5

Browse files
committed
fix(auth): check for null user before attempting to transform
Fixes angular#251
1 parent d9a6ae7 commit 981f0f5

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/providers/auth.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,20 @@ describe('FirebaseAuth', () => {
528528
expect(app.auth().signOut).toHaveBeenCalled();
529529
});
530530
});
531+
532+
533+
describe('getAuth()', () => {
534+
it('should return null when no user is logged in', () => {
535+
authSpy['currentUser'] = null;
536+
expect(afAuth.getAuth()).toBe(null);
537+
});
538+
539+
540+
it('should return authState if user is logged in', () => {
541+
authSpy['currentUser'] = firebaseUser;
542+
expect(afAuth.getAuth().uid).toEqual(AngularFireAuthState.uid);
543+
})
544+
});
531545
});
532546
});
533547

src/providers/auth_backend.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export interface TwitterCredential extends CommonOAuthCredential {
7070
export type OAuthCredential = CommonOAuthCredential | GoogleCredential | TwitterCredential;
7171

7272
export function authDataToAuthState(authData: firebase.User, providerData?: OAuthCredential): FirebaseAuthState {
73+
if (!authData) return null;
7374
let providerId;
7475
let { uid } = authData;
7576
let authState: FirebaseAuthState = { auth: authData, uid, provider: null };

0 commit comments

Comments
 (0)