Skip to content

Commit 4fbe5f0

Browse files
committed
Add LiteAppCheckTokenProvider.
1 parent d5462fe commit 4fbe5f0

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

packages/firestore/lite/register.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { Component, ComponentType } from '@firebase/component';
2424

2525
import { version } from '../package.json';
2626
import {
27-
FirebaseAppCheckTokenProvider,
27+
LiteAppCheckTokenProvider,
2828
LiteCredentialsProvider
2929
} from '../src/api/credentials';
3030
import { setSDKVersion } from '../src/core/version';
@@ -47,7 +47,7 @@ export function registerFirestore(): void {
4747
const firestoreInstance = new Firestore(
4848
app,
4949
new LiteCredentialsProvider(container.getProvider('auth-internal')),
50-
new FirebaseAppCheckTokenProvider(
50+
new LiteAppCheckTokenProvider(
5151
container.getProvider('app-check-internal')
5252
)
5353
);

packages/firestore/src/api/credentials.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,46 @@ export class EmptyAppCheckTokenProvider implements CredentialsProvider<string> {
579579
shutdown(): void {}
580580
}
581581

582+
/** AppCheck token provider for the Lite SDK. */
583+
export class LiteAppCheckTokenProvider implements CredentialsProvider<String> {
584+
private appCheck: FirebaseAppCheckInternal | null = null;
585+
586+
constructor(
587+
private appCheckProvider: Provider<AppCheckInternalComponentName>
588+
) {
589+
appCheckProvider.onInit(appCheck => {
590+
this.appCheck = appCheck;
591+
});
592+
}
593+
594+
getToken(): Promise<Token | null> {
595+
if (!this.appCheck) {
596+
return Promise.resolve(null);
597+
}
598+
599+
return this.appCheck.getToken().then(tokenResult => {
600+
if (tokenResult) {
601+
hardAssert(
602+
typeof tokenResult.token === 'string',
603+
'Invalid tokenResult returned from getToken():' + tokenResult
604+
);
605+
return new AppCheckToken(tokenResult.token);
606+
} else {
607+
return null;
608+
}
609+
});
610+
}
611+
612+
invalidateToken(): void {}
613+
614+
start(
615+
asyncQueue: AsyncQueue,
616+
changeListener: CredentialChangeListener<string>
617+
): void {}
618+
619+
shutdown(): void {}
620+
}
621+
582622
/**
583623
* Builds a CredentialsProvider depending on the type of
584624
* the credentials passed in.

0 commit comments

Comments
 (0)