Skip to content

Commit b46a29a

Browse files
authored
docs(app-check, ios): update installation steps
Additional modifications to AppDelegate.mm are required in order to load the RNFBAppCheckModule. Without initializing the AppCheckModule before calling [FIRApp configure], the setup of a custom provider will fail.
1 parent 1631dd4 commit b46a29a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

docs/app-check/usage/index.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,29 @@ For instructions on how to generate required keys and register an app for the de
8787

8888
You must call initialize the AppCheck module prior to calling any firebase back-end services for App Check to function.
8989

90+
To do that, edit your `ios/ProjectName/AppDelegate.mm` and add the following two lines:
91+
92+
```objectivec
93+
#import "AppDelegate.h"
94+
#import "RNFBAppCheckModule.h" // ⬅️ ADD THIS LINE
95+
#import <Firebase.h>
96+
...
97+
98+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
99+
{
100+
// Initialize RNFBAppCheckModule, it sets the custom RNFBAppCheckProviderFactory
101+
// which lets us configure any of the available native platform providers,
102+
// and reconfigure if needed, dynamically after `[FIRApp configure]` just like the other platforms.
103+
104+
[RNFBAppCheckModule sharedInstance]; // ⬅️ ADD THIS LINE BEFORE [FIRApp configure]
105+
106+
[FIRApp configure];
107+
108+
...
109+
}
110+
111+
```
112+
90113
There are several differences between the web, Apple, and Android platform SDKs produced by Firebase, which react-native-firebase smooths over to give you a common, firebase-js-sdk compatible API.
91114

92115
How do we do this? We use the standard firebase-js-sdk v9 API `initializeAppCheck`, and take advantage of its parameters which allow the use of an `AppCheckOptions` argument that itself allows a `CustomProvider`.
@@ -125,6 +148,22 @@ Once you have the custom provider configured, install it in app-check using the
125148
firebase.appCheck().initializeAppCheck({ provider: rnfbProvider, isTokenAutoRefreshEnabled: true });
126149
```
127150

151+
### Verify AppCheck was initialized correctly
152+
153+
After initializing the custom provider, you can verify AppCheck is working by logging a response from the token server:
154+
155+
```javascript
156+
try {
157+
const { token } = await firebase.appCheck().getToken(true);
158+
159+
if (token.length > 0) {
160+
console.log('AppCheck verification passed');
161+
}
162+
} catch (error) {
163+
console.log('AppCheck verification failed');
164+
}
165+
```
166+
128167
## Automatic Data Collection
129168

130169
App Check has an "tokenAutoRefreshEnabled" setting. This may cause App Check to attempt a remote App Check token fetch prior to user consent. In certain scenarios, like those that exist in GDPR-compliant apps running for the first time, this may be unwanted.

0 commit comments

Comments
 (0)