Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛] app-check modular API doesn't seem to conform to provided docs #8361

Open
1 of 10 tasks
gigilibala opened this issue Feb 23, 2025 · 3 comments
Open
1 of 10 tasks
Labels
impact: web-implementation An API in RNFB does not conform to the Firebase Web SDK Needs Attention plugin: app-check Firebase AppCheck type: bug New bug report

Comments

@gigilibala
Copy link

Issue

Looking at the AppCheck implementation in rnfirebase, it doesn't seem like it follows the docs provided in the rnfirebase.io.

Code snippet from docs is as follows:

import { ReactNativeFirebaseAppCheckProvider } from `@react-native-firebase/app-check`;
import { initializeAppCheck  } from `@react-native-firebase/app-check`;

rnfbProvider = new ReactNativeFirebaseAppCheckProvider();
rnfbProvider.configure({
  android: {
    provider: __DEV__ ? 'debug' : 'playIntegrity',
    debugToken: 'some token you have configured for your project firebase web console',
  },
  apple: {
    provider: __DEV__ ? 'debug' : 'appAttestWithDeviceCheckFallback',
    debugToken: 'some token you have configured for your project firebase web console',
  },
  web: {
    provider: 'reCaptchaV3',
    siteKey: 'unknown',
  },
});

const appCheck = initializeAppCheck({ provider: rnfbProvider, isTokenAutoRefreshEnabled

However, most I could build (working!) with the rnfirebase API is as follows:

import { getApp } from "@react-native-firebase/app";
import getAppCheck, { getToken, initializeAppCheck } from "@react-native-firebase/app-check";

const app = getApp()
const appCheck = getAppCheck(app)

const provider = appCheck.newReactNativeFirebaseAppCheckProvider();
provider.configure({
  android: {
    provider: "debug",
  },
  apple: {
    provider: "debug",
  },
  isTokenAutoRefreshEnabled: true,
});

await initializeAppCheck(app, {
  provider,
});

const token = await getToken(appCheck, false);
if (token.token.length <= 0) {
  throw new Error("AppCheck token was not initialized");
}

There are few issues I see:

  • initializeAppCheck is ought to return an AppCheck instance, but the signature shows an App instance instead. source:
    export async function initializeAppCheck(app, options) {
  • There is no getAppCheck exported, but I assume this expected since we need to initialize it through initializeAppCheck. right?
  • There is no exported newReactNativeFirebaseAppCheckProvider() or ReactNativeFirebaseAppCheckProvider. This is a problem because in order to initialize the appCheck I'd need the result of provider.configure, but currently I need the appCheck instance to get build the provider.

I maybe wrong in all above (and hence these are expected API), but these are observations I just had. Appreciate if I can get feedback whether assumptions above are correct or not.

Thanks.


Project Files

Javascript

Click To Expand

package.json:

# N/A

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
# N/A

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

react-native info output:

 OUTPUT GOES HERE
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • e.g. 5.4.3
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • Y/N & VERSION


@mikehardy
Copy link
Collaborator

mikehardy commented Feb 23, 2025

Was just in this area, using our e2e tests as the proof of it working - I think you may be right about the initializeAppCheck not returning the correct type in the typings, but it returns an AppCheck instance in reality, here's what I see working correctly in our e2e tests, all platforms native platforms:

before(async function () {
const { initializeAppCheck, ReactNativeFirebaseAppCheckProvider } = appCheckModular;
let provider;
if (!Platform.other) {
provider = new ReactNativeFirebaseAppCheckProvider();
provider.configure({
android: {
provider: 'debug',
debugToken: '698956B2-187B-49C6-9E25-C3F3530EEBAF',
},
apple: {
provider: 'debug',
debugToken: '698956B2-187B-49C6-9E25-C3F3530EEBAF',
},
web: {
provider: 'debug',
siteKey: 'none',
},
});
} else {
provider = new ReactNativeFirebaseAppCheckProvider({
getToken() {
return FirebaseHelpers.fetchAppCheckToken();
},
});
}
// Our tests configure a debug provider with shared secret so we should get a valid token
appCheckInstance = await initializeAppCheck(undefined, {
provider,
isTokenAutoRefreshEnabled: false,
});
});

@gigilibala
Copy link
Author

Hi,
Thanks for the response.
How about the ReactNativeFirebaseAppCheckProvider? It doesn't seem to have been exported properly.

Image

@mikehardy
Copy link
Collaborator

You're correct - sorry about that - when I was in there I exported the implementation, so it works in javascript but the types are definitely not correct so typescript won't buy it.

You could ts-ignore the import line temporarily (maybe have a second one to just ts-ignore this specific import...) and just

import { ReactNativeFirebaseAppCheckProvider } from `@react-native-firebase/app`

and it will work to then new ReactNativeFirebaseAppCheckProvider(); until I fix the types. My e2e test shows it works at least, just doesn't type check.

You cannot get rid of the getAppCheck namespaced import until I fix the modular implementation error and return AppCheck from initializeAppCheck, as that's also a mistake (thanks for pointing it out)

should conform to https://firebase.google.com/docs/reference/js/app-check.md#initializeappcheck_5548dfc and return AppCheck type

Will post a PR to fix that when I get a moment, and tag this issue with it for close

@mikehardy mikehardy added impact: web-implementation An API in RNFB does not conform to the Firebase Web SDK plugin: app-check Firebase AppCheck labels Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact: web-implementation An API in RNFB does not conform to the Firebase Web SDK Needs Attention plugin: app-check Firebase AppCheck type: bug New bug report
Projects
None yet
Development

No branches or pull requests

2 participants