1515 *
1616 */
1717
18+ #if __has_include(<Firebase/Firebase.h>)
1819#import < Firebase/Firebase.h>
19- #import < FirebaseAppCheck/FIRAppCheck.h>
20+ #elif __has_include(<FirebaseAppCheck/FirebaseAppCheck.h>)
21+ #import < FirebaseAppCheck/FirebaseAppCheck.h>
22+ #import < FirebaseCore/FirebaseCore.h>
23+ #else
24+ @import FirebaseCore;
25+ @import FirebaseAppCheck;
26+ #endif
2027
2128#import < React/RCTUtils.h>
2229
@@ -53,7 +60,8 @@ + (instancetype)sharedInstance {
5360 : (BOOL )isTokenAutoRefreshEnabled
5461 : (RCTPromiseResolveBlock)resolve rejecter
5562 : (RCTPromiseRejectBlock)reject) {
56- DLog (@" deprecated API, provider will be deviceCheck / token refresh %d for app %@ " ,
63+ DLog (@" deprecated API, provider will be deviceCheck / token refresh %d for "
64+ @" app %@ " ,
5765 isTokenAutoRefreshEnabled, firebaseApp.name );
5866 [[RNFBAppCheckModule sharedInstance ].providerFactory configure: firebaseApp
5967 providerName: @" deviceCheck"
@@ -86,8 +94,8 @@ + (instancetype)sharedInstance {
8694 appCheck.isTokenAutoRefreshEnabled = isTokenAutoRefreshEnabled;
8795}
8896
89- // Not present in JS or Android - it is iOS-specific so we only call this in testing - it is not in
90- // index.d.ts
97+ // Not present in JS or Android - it is iOS-specific so we only call this in
98+ // testing - it is not in index.d.ts
9199RCT_EXPORT_METHOD (isTokenAutoRefreshEnabled
92100 : (FIRApp *)firebaseApp
93101 : (RCTPromiseResolveBlock)resolve rejecter
@@ -105,33 +113,36 @@ + (instancetype)sharedInstance {
105113 : (RCTPromiseRejectBlock)reject) {
106114 FIRAppCheck *appCheck = [FIRAppCheck appCheckWithApp: firebaseApp];
107115 DLog (@" appName %@ " , firebaseApp.name );
108- [appCheck
109- tokenForcingRefresh: forceRefresh
110- completion: ^(FIRAppCheckToken *_Nullable token, NSError *_Nullable error) {
111- if (error != nil ) {
112- // Handle any errors if the token was not retrieved.
113- DLog (@" RNFBAppCheck - getToken - Unable to retrieve App Check token: %@ " , error);
114- [RNFBSharedUtils rejectPromiseWithUserInfo: reject
115- userInfo: (NSMutableDictionary *)@{
116- @" code" : @" token-error" ,
117- @" message" : [error localizedDescription ],
118- }];
119- return ;
120- }
121- if (token == nil ) {
122- DLog (@" RNFBAppCheck - getToken - Unable to retrieve App Check token." );
123- [RNFBSharedUtils rejectPromiseWithUserInfo: reject
124- userInfo: (NSMutableDictionary *)@{
125- @" code" : @" token-null" ,
126- @" message" : @" no token fetched" ,
127- }];
128- return ;
129- }
130-
131- NSMutableDictionary *tokenResultDictionary = [NSMutableDictionary new ];
132- tokenResultDictionary[@" token" ] = token.token ;
133- resolve (tokenResultDictionary);
134- }];
116+ [appCheck tokenForcingRefresh: forceRefresh
117+ completion: ^(FIRAppCheckToken *_Nullable token, NSError *_Nullable error) {
118+ if (error != nil ) {
119+ // Handle any errors if the token was not retrieved.
120+ DLog (@" RNFBAppCheck - getToken - Unable to retrieve App "
121+ @" Check token: %@ " ,
122+ error);
123+ [RNFBSharedUtils
124+ rejectPromiseWithUserInfo: reject
125+ userInfo: (NSMutableDictionary *)@{
126+ @" code" : @" token-error" ,
127+ @" message" : [error localizedDescription ],
128+ }];
129+ return ;
130+ }
131+ if (token == nil ) {
132+ DLog (@" RNFBAppCheck - getToken - Unable to retrieve App "
133+ @" Check token." );
134+ [RNFBSharedUtils rejectPromiseWithUserInfo: reject
135+ userInfo: (NSMutableDictionary *)@{
136+ @" code" : @" token-null" ,
137+ @" message" : @" no token fetched" ,
138+ }];
139+ return ;
140+ }
141+
142+ NSMutableDictionary *tokenResultDictionary = [NSMutableDictionary new ];
143+ tokenResultDictionary[@" token" ] = token.token ;
144+ resolve (tokenResultDictionary);
145+ }];
135146}
136147
137148RCT_EXPORT_METHOD (getLimitedUseToken
@@ -140,32 +151,35 @@ + (instancetype)sharedInstance {
140151 : (RCTPromiseRejectBlock)reject) {
141152 FIRAppCheck *appCheck = [FIRAppCheck appCheckWithApp: firebaseApp];
142153 DLog (@" appName %@ " , firebaseApp.name );
143- [appCheck limitedUseTokenWithCompletion: ^(FIRAppCheckToken *_Nullable token,
144- NSError *_Nullable error) {
145- if (error != nil ) {
146- // Handle any errors if the token was not retrieved.
147- DLog (@" RNFBAppCheck - getLimitedUseToken - Unable to retrieve App Check token: %@ " , error);
148- [RNFBSharedUtils rejectPromiseWithUserInfo: reject
149- userInfo: (NSMutableDictionary *)@{
150- @" code" : @" token-error" ,
151- @" message" : [error localizedDescription ],
152- }];
153- return ;
154- }
155- if (token == nil ) {
156- DLog (@" RNFBAppCheck - getLimitedUseToken - Unable to retrieve App Check token." );
157- [RNFBSharedUtils rejectPromiseWithUserInfo: reject
158- userInfo: (NSMutableDictionary *)@{
159- @" code" : @" token-null" ,
160- @" message" : @" no token fetched" ,
161- }];
162- return ;
163- }
164-
165- NSMutableDictionary *tokenResultDictionary = [NSMutableDictionary new ];
166- tokenResultDictionary[@" token" ] = token.token ;
167- resolve (tokenResultDictionary);
168- }];
154+ [appCheck
155+ limitedUseTokenWithCompletion: ^(FIRAppCheckToken *_Nullable token, NSError *_Nullable error) {
156+ if (error != nil ) {
157+ // Handle any errors if the token was not retrieved.
158+ DLog (@" RNFBAppCheck - getLimitedUseToken - Unable to retrieve App Check "
159+ @" token: %@ " ,
160+ error);
161+ [RNFBSharedUtils rejectPromiseWithUserInfo: reject
162+ userInfo: (NSMutableDictionary *)@{
163+ @" code" : @" token-error" ,
164+ @" message" : [error localizedDescription ],
165+ }];
166+ return ;
167+ }
168+ if (token == nil ) {
169+ DLog (@" RNFBAppCheck - getLimitedUseToken - Unable to retrieve App Check "
170+ @" token." );
171+ [RNFBSharedUtils rejectPromiseWithUserInfo: reject
172+ userInfo: (NSMutableDictionary *)@{
173+ @" code" : @" token-null" ,
174+ @" message" : @" no token fetched" ,
175+ }];
176+ return ;
177+ }
178+
179+ NSMutableDictionary *tokenResultDictionary = [NSMutableDictionary new ];
180+ tokenResultDictionary[@" token" ] = token.token ;
181+ resolve (tokenResultDictionary);
182+ }];
169183}
170184
171185@end
0 commit comments