Skip to content

Commit b4a9a96

Browse files
committed
Add logs and comments, and tidy tests
1 parent 8ce92e6 commit b4a9a96

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

packages/auth/src/core/auth/auth_impl.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { _getUserLanguage } from '../util/navigator';
6363
import { _getClientVersion } from '../util/version';
6464
import { HttpHeader } from '../../api';
6565
import { AuthMiddlewareQueue } from './middleware';
66+
import { _logWarn } from '../util/log';
6667

6768
interface AsyncAction {
6869
(): Promise<void>;
@@ -650,11 +651,6 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
650651

651652
// If the App Check service exists, add the App Check token in the headers
652653
const appCheckToken = await this._getAppCheckToken();
653-
// TODO: What do we want to do if there is an error getting the token?
654-
// Context: appCheck.getToken() will never throw even if an error happened.
655-
// In the error case, a dummy token will be returned along with an error field describing
656-
// the error. In general, we shouldn't care about the error condition and just use
657-
// the token (actual or dummy) to send requests.
658654
if (appCheckToken) {
659655
headers[HttpHeader.X_FIREBASE_APP_CHECK] = appCheckToken;
660656
}
@@ -665,6 +661,15 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
665661
const appCheckTokenResult = await this.appCheckServiceProvider
666662
.getImmediate({ optional: true })
667663
?.getToken();
664+
if (appCheckTokenResult?.error) {
665+
// Context: appCheck.getToken() will never throw even if an error happened.
666+
// In the error case, a dummy token will be returned along with an error field describing
667+
// the error. In general, we shouldn't care about the error condition and just use
668+
// the token (actual or dummy) to send requests.
669+
_logWarn(
670+
`Error while retrieving App Check token: ${appCheckTokenResult.error}`
671+
);
672+
}
668673
return appCheckTokenResult?.token;
669674
}
670675
}

packages/auth/src/core/util/handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export async function _getRedirectUrl(
121121
? `${FIREBASE_APP_CHECK_FRAGMENT_ID}=${encodeURIComponent(appCheckToken)}`
122122
: '';
123123

124+
// Start at index 1 to skip the leading '&' in the query string
124125
return `${getHandlerBase(auth)}?${querystring(paramsDict).slice(
125126
1
126127
)}#${appCheckTokenFragment}`;

packages/auth/src/core/util/log.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export function _logDebug(msg: string, ...args: string[]): void {
3737
}
3838
}
3939

40+
export function _logWarn(msg: string, ...args: string[]): void {
41+
if (logClient.logLevel <= LogLevel.WARN) {
42+
logClient.warn(`Auth (${SDK_VERSION}): ${msg}`, ...args);
43+
}
44+
}
45+
4046
export function _logError(msg: string, ...args: string[]): void {
4147
if (logClient.logLevel <= LogLevel.ERROR) {
4248
logClient.error(`Auth (${SDK_VERSION}): ${msg}`, ...args);

packages/auth/src/platform_browser/popup_redirect.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe('platform_browser/popup_redirect', () => {
151151
const matches = (popupUrl as string).match(/.*?#(.*)/);
152152
expect(matches).not.to.be.null;
153153
const fragment = matches![1];
154-
expect(fragment).not.to.include('fac');
154+
expect(fragment).to.be.empty;
155155
});
156156

157157
it('does not add the App Check token in the url fragment if controller unavailable', async () => {
@@ -165,7 +165,7 @@ describe('platform_browser/popup_redirect', () => {
165165
const matches = (popupUrl as string).match(/.*?#(.*)/);
166166
expect(matches).not.to.be.null;
167167
const fragment = matches![1];
168-
expect(fragment).not.to.include('fac');
168+
expect(fragment).to.be.empty;
169169
});
170170

171171
it('throws an error if apiKey is unspecified', async () => {
@@ -259,7 +259,7 @@ describe('platform_browser/popup_redirect', () => {
259259
const matches = newWindowLocation.match(/.*?#(.*)/);
260260
expect(matches).not.to.be.null;
261261
const fragment = matches![1];
262-
expect(fragment).not.to.include('fac');
262+
expect(fragment).to.be.empty;
263263
});
264264

265265
it('does not add the App Check token in the url fragment if controller unavailable', async () => {
@@ -279,7 +279,7 @@ describe('platform_browser/popup_redirect', () => {
279279
const matches = newWindowLocation.match(/.*?#(.*)/);
280280
expect(matches).not.to.be.null;
281281
const fragment = matches![1];
282-
expect(fragment).not.to.include('fac');
282+
expect(fragment).to.be.empty;
283283
});
284284

285285
it('throws an error if authDomain is unspecified', async () => {

0 commit comments

Comments
 (0)