Skip to content

Commit

Permalink
Fixed removal of database emulatortokenprovider
Browse files Browse the repository at this point in the history
  • Loading branch information
maneesht committed May 9, 2024
1 parent ed9123d commit 81ee516
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
14 changes: 0 additions & 14 deletions common/api-review/data-connect.api.md
Expand Up @@ -104,20 +104,6 @@ export interface DataConnectTransport {
// @public (undocumented)
export type DataSource = typeof SOURCE_CACHE | typeof SOURCE_SERVER;

// @public (undocumented)
export class EmulatorTokenProvider implements AuthTokenProvider {
constructor(accessToken: string);
// (undocumented)
addTokenChangeListener(listener: AuthTokenListener): void;
// (undocumented)
getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData>;
// (undocumented)
notifyForInvalidToken(): void;
static OWNER: string;
// (undocumented)
removeTokenChangeListener(listener: (token: string | null) => void): void;
}

// @public (undocumented)
export function executeMutation<Data, Variables>(mutationRef: MutationRef<Data, Variables>): MutationPromise<Data, Variables>;

Expand Down
21 changes: 0 additions & 21 deletions packages/data-connect/src/core/FirebaseAuthProvider.ts
Expand Up @@ -78,25 +78,4 @@ export class FirebaseAuthProvider implements AuthTokenProvider {
.then(auth => auth.removeAuthTokenListener(listener));
}
}
export class EmulatorTokenProvider implements AuthTokenProvider {
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
static OWNER = 'owner';

constructor(private accessToken: string) {}

getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData> {
return Promise.resolve({
accessToken: this.accessToken
});
}

addTokenChangeListener(listener: AuthTokenListener): void {
// Invoke the listener immediately to match the behavior in Firebase Auth
// (see packages/auth/src/auth.js#L1807)
listener(this.accessToken);
}

removeTokenChangeListener(listener: (token: string | null) => void): void {}

notifyForInvalidToken(): void {}
}
24 changes: 24 additions & 0 deletions packages/database/src/core/AuthTokenProvider.ts
Expand Up @@ -120,3 +120,27 @@ export class FirebaseAuthTokenProvider implements AuthTokenProvider {
warn(errorMessage);
}
}

/* AuthTokenProvider that supplies a constant token. Used by Admin SDK or mockUserToken with emulators. */
export class EmulatorTokenProvider implements AuthTokenProvider {
/** A string that is treated as an admin access token by the RTDB emulator. Used by Admin SDK. */
static OWNER = 'owner';

constructor(private accessToken: string) {}

getToken(forceRefresh: boolean): Promise<FirebaseAuthTokenData> {
return Promise.resolve({
accessToken: this.accessToken
});
}

addTokenChangeListener(listener: (token: string | null) => void): void {
// Invoke the listener immediately to match the behavior in Firebase Auth
// (see packages/auth/src/auth.js#L1807)
listener(this.accessToken);
}

removeTokenChangeListener(listener: (token: string | null) => void): void {}

notifyForInvalidToken(): void {}
}

0 comments on commit 81ee516

Please sign in to comment.