React Native App Check

761 views
Skip to first unread message

Aurélien Houdbert

unread,
Aug 28, 2022, 1:02:24 PM8/28/22
to Firebase Google Group
Hello everyone !

I'm trying to use App Check on my react native app :)
this documentation (https://rnfirebase.io/app-check/usage) doesn't have much info on how to setup the package so I'm trying to follow this documentation instead (https://firebase.google.com/docs/app-check?hl=en). The issue mostly concerns the android part where I don't understand this section (https://firebase.google.com/docs/app-check/android/safetynet-provider?hl=en#initialize) and I don't know where I should put this piece of code in my react native project...

FirebaseApp.initializeApp(/*context=*/ this);
FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance();
firebaseAppCheck.installAppCheckProviderFactory(
        SafetyNetAppCheckProviderFactory.getInstance());

Does anyone has a clear tutorial on how to use app check under react native ?

Thanks a lot !

Stephan Strecker

unread,
Aug 29, 2022, 3:27:37 AM8/29/22
to fireba...@googlegroups.com
Hi,

attached you can see the Code that we are using at the moment:

firebaseApp = firebase.app();
dbApp = firebaseApp.firestore();
authApp = firebaseApp.auth();
functionsApp = firebaseApp.functions("europe-west1");
storageApp = firebaseApp.storage("gs://" + firebaseConfig.storageBucket);
realtimeDatabaseApp = firebaseApp.database(firebaseConfig.databaseURL);

analyticsApp = firebaseApp.analytics();
appCheckApp = firebaseApp.appCheck();

remoteConfigApp = firebaseApp.remoteConfig();

try {
if (Platform.OS === "ios") {
console.log("AppCheck activated by default");
await appCheckApp.activate("ignored", true);
} else await appCheckApp.activate("ignored", true);
} catch (e) {
console.log("error", e);
}

try {
let appCheckTokenResponse = await appCheckApp.getToken(
/* forceRefresh= */ false
);
console.log("appcheck", appCheckTokenResponse);
} catch (err) {
// Handle any errors if the token was not retrieved.
console.log("appcheck error", err);
}

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/b482b8ef-b019-4c23-a536-2d2e790e858bn%40googlegroups.com.

Aurélien Houdbert

unread,
Aug 31, 2022, 1:52:21 AM8/31/22
to Firebase Google Group
Hi,

Thanks for your answer ! In which file did you insert this piece of code?

Stephan Strecker

unread,
Aug 31, 2022, 7:37:47 AM8/31/22
to fireba...@googlegroups.com
we have an own class that is handling all backend interactions. this class is initiated at app start.
I assume you already have a place where you initiate your firebase instance. thats the place to do it also for appcheck

Reply all
Reply to author
Forward
0 new messages