From 5a880c666377b14aa7d68fe5e8db42a1b5aaf218 Mon Sep 17 00:00:00 2001 From: Yuchen Shi Date: Mon, 9 Dec 2019 16:32:06 -0800 Subject: [PATCH] Implement addAuthTokenListener in testing. Fix #2417. (#2423) --- packages/testing/src/api/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/testing/src/api/index.ts b/packages/testing/src/api/index.ts index 94b6eaf7918..b4114e2de76 100644 --- a/packages/testing/src/api/index.ts +++ b/packages/testing/src/api/index.ts @@ -127,7 +127,6 @@ function initializeApp( } const appName = 'app-' + new Date().getTime() + '-' + Math.random(); let app = firebase.initializeApp(appOptions, appName); - // hijacking INTERNAL.getToken to bypass FirebaseAuth and allows specifying of auth headers if (accessToken) { const mockAuthComponent = new Component( 'auth-internal', @@ -135,7 +134,10 @@ function initializeApp( ({ getToken: async () => ({ accessToken: accessToken }), getUid: () => null, - addAuthTokenListener: () => {}, + addAuthTokenListener: (listener) => { + // Call listener once immediately with predefined accessToken. + listener(accessToken); + }, removeAuthTokenListener: () => {} } as FirebaseAuthInternal), ComponentType.PRIVATE