I'm integrating Firebase App Check into my existing Angular project. Since I am using Capacitor, my web application and iOS app share the same codebase.
For the web version, I added provideAppCheck()
to my Angular module's imports
section. Here’s how my imports look:
provideFirebaseApp(() => initializeApp(environment.firebase)),
provideAppCheck(() => initializeAppCheck(undefined, {
provider: new ReCaptchaV3Provider('KEY'),
isTokenAutoRefreshEnabled: true // Enables automatic token refresh
})),
provideAuth(() => {
if (Capacitor.isNativePlatform()) {
return initializeAuth(getApp(), {
persistence: indexedDBLocalPersistence,
});
} else {
return getAuth();
}
}),
provideDatabase(() => getDatabase()),
On the web, this setup works perfectly—I can access the Realtime Database, which has App Check enforcement enabled.
iOS Implementation with @capacitor-firebase/app-check
For the iOS version, I opted to use @capacitor-firebase/app-check
. I initialize Firebase App Check in the AppModule
constructor, along with the required setup in Xcode.
export class AppModule {
constructor() {
if (Capacitor.getPlatform() !== 'web') {
this.initialize_app_check();
}
}
private async initialize_app_check() {
try {
const options: InitializeOptions = {
debug: false,
};
await FirebaseAppCheck.initialize(options);
const toOptions: GetTokenOptions = {
forceRefresh: true,
};
const { token } = await FirebaseAppCheck.getToken(toOptions);
console.log(token);
} catch (e) {
console.error(e);
}
}
}
Missing App Check Token on iOS
Even though FirebaseAppCheck.initialize()
successfully logs a token, when I try to call the Realtime Database from my iOS app, I get a warning that no token exists, and access is blocked.
This issue persists even when I manually check for the token just before making the database request:
const token = await this.getAppCheckToken();
if (!token) {
console.error('Missing App Check token');
return;
}
const lp_ref = ref(this.database, `/functionale/${this.current_app}/home/last_published`);
const snapshot = await get(lp_ref);
@firebase/database: FIREBASE WARNING: Missing appcheck token
I tried adding the AppCheck in Xcode directly (AppDelegate). I notice the same behavior here: I can successfully generate a token, but not call the Realtime Database.
I would really appreciate any guidance on:
- Why the token isn’t recognized on iOS despite being logged.
- How to properly attach the App Check token to Firebase Database requests in Capacitor-based Angular apps.