Skip to content

Commit

Permalink
Expose addFrameworkForLogging. (#4786)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchenshi authored Apr 15, 2021
1 parent 31126af commit 03e97b8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
8 changes: 8 additions & 0 deletions packages-exp/auth-compat-exp/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ export class Auth
}
return convertCredential(this._delegate, Promise.resolve(credential));
}

// This function should only be called by frameworks (e.g. FirebaseUI-web) to log their usage.
// It is not intended for direct use by developer apps. NO jsdoc here to intentionally leave it
// out of autogenerated documentation pages to reduce accidental misuse.
addFrameworkForLogging(framework: string): void {
exp.addFrameworkForLogging(this._delegate, framework);
}

onAuthStateChanged(
nextOrObserver: Observer<unknown> | ((a: compat.User | null) => unknown),
errorFn?: (error: compat.Error) => unknown,
Expand Down
10 changes: 10 additions & 0 deletions packages-exp/auth-exp/internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* limitations under the License.
*/

import { _castAuth } from '../src/core/auth/auth_impl';
import { Auth } from '../src/model/public_types';

/**
* This interface is intended only for use by @firebase/auth-compat-exp, do not use directly
*/
Expand Down Expand Up @@ -45,3 +48,10 @@ export { _getRedirectResult } from '../src/platform_browser/strategies/redirect'
export { cordovaPopupRedirectResolver } from '../src/platform_cordova/popup_redirect/popup_redirect';
export { FetchProvider } from '../src/core/util/fetch_provider';
export { SAMLAuthCredential } from '../src/core/credentials/saml';

// This function should only be called by frameworks (e.g. FirebaseUI-web) to log their usage.
// It is not intended for direct use by developer apps. NO jsdoc here to intentionally leave it out
// of autogenerated documentation pages to reduce accidental misuse.
export function addFrameworkForLogging(auth: Auth, framework: string): void {
_castAuth(auth)._logFramework(framework);
}
2 changes: 1 addition & 1 deletion packages-exp/auth-exp/src/core/auth/auth_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
private frameworks: string[] = [];
private clientVersion: string;
_logFramework(framework: string): void {
if (this.frameworks.includes(framework)) {
if (!framework || this.frameworks.includes(framework)) {
return;
}
this.frameworks.push(framework);
Expand Down
12 changes: 1 addition & 11 deletions packages-exp/auth-exp/src/core/util/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,8 @@ export const enum ClientPlatform {
WORKER = 'Worker'
}

const enum ClientFramework {
// No other framework used.
DEFAULT = 'FirebaseCore-web',
// Firebase Auth used with FirebaseUI-web.
// TODO: Pass this in when used in conjunction with FirebaseUI
FIREBASEUI = 'FirebaseUI-web'
}

/*
* Determine the SDK version string
*
* TODO: This should be set on the Auth object during initialization
*/
export function _getClientVersion(
clientPlatform: ClientPlatform,
Expand All @@ -65,6 +55,6 @@ export function _getClientVersion(
}
const reportedFrameworks = frameworks.length
? frameworks.join(',')
: ClientFramework.DEFAULT;
: 'FirebaseCore-web'; /* default value if no other framework is used */
return `${reportedPlatform}/${ClientImplementation.CORE}/${SDK_VERSION}/${reportedFrameworks}`;
}

0 comments on commit 03e97b8

Please sign in to comment.