Skip to content

Commit

Permalink
feat: firebase app-check
Browse files Browse the repository at this point in the history
  • Loading branch information
KestasVenslauskas committed Jul 25, 2024
1 parent e34984f commit 8a9c0cf
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
2 changes: 2 additions & 0 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import PlayerProvider from './app/components/videoComponent/context/PlayerProvid
import useNotificationsPermission from './app/util/useNotificationsPermission';
import useGoogleAnalyticsSetup from './app/util/useGoogleAnalyticsSetup';
import ThemeProvider from './app/theme/ThemeProvider';
import useAppCheckSetup from './app/util/useAppCheckSetup';

const ReduxProvider: React.FC<React.PropsWithChildren<{}>> = ({children}) => {
return (
Expand All @@ -26,6 +27,7 @@ const ReduxProvider: React.FC<React.PropsWithChildren<{}>> = ({children}) => {
};

const App: React.FC = () => {
useAppCheckSetup();
useNotificationsPermission();
useAppTrackingPermission();
useGoogleAnalyticsSetup();
Expand Down
38 changes: 38 additions & 0 deletions app/util/useAppCheckSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {firebase} from '@react-native-firebase/app-check';
import {useEffect} from 'react';

const rnfbProvider = firebase.appCheck().newReactNativeFirebaseAppCheckProvider();
rnfbProvider.configure({
android: {
provider: __DEV__ ? 'debug' : 'playIntegrity',
debugToken: '62BDDD90-4D52-41F2-9F2C-6DC6F3B398C9',
},
apple: {
provider: __DEV__ ? 'debug' : 'appAttestWithDeviceCheckFallback',
debugToken: '36DD3397-3EFC-4FB1-BD2B-8AF1151D7B85',
},
});

const setup = async () => {
await firebase.appCheck().initializeAppCheck({provider: rnfbProvider, isTokenAutoRefreshEnabled: true});
};

const verify = async () => {
try {
const {token} = await firebase.appCheck().getToken(true);

if (token.length > 0) {
console.log('AppCheck verification passed');
}
} catch (error) {
console.warn('AppCheck verification failed');
}
};

const useAppCheckSetup = () => {
useEffect(() => {
setup().then(verify).catch(console.error);
}, []);
};

export default useAppCheckSetup;
27 changes: 26 additions & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,10 @@ PODS:
- abseil/meta/type_traits
- abseil/xcprivacy
- abseil/xcprivacy (1.20240116.2)
- AppCheckCore (10.19.2):
- GoogleUtilities/Environment (~> 7.13)
- GoogleUtilities/UserDefaults (~> 7.13)
- PromisesObjC (~> 2.3)
- boost (1.83.0)
- BoringSSL-GRPC (0.0.32):
- BoringSSL-GRPC/Implementation (= 0.0.32)
Expand All @@ -967,6 +971,9 @@ PODS:
- ReactCommon/turbomodule/core (= 0.73.8)
- Firebase/Analytics (10.24.0):
- Firebase/Core
- Firebase/AppCheck (10.24.0):
- Firebase/CoreOnly
- FirebaseAppCheck (~> 10.24.0)
- Firebase/Core (10.24.0):
- Firebase/CoreOnly
- FirebaseAnalytics (~> 10.24.0)
Expand Down Expand Up @@ -999,6 +1006,12 @@ PODS:
- GoogleUtilities/Network (~> 7.11)
- "GoogleUtilities/NSData+zlib (~> 7.11)"
- nanopb (< 2.30911.0, >= 2.30908.0)
- FirebaseAppCheck (10.24.0):
- AppCheckCore (~> 10.18)
- FirebaseAppCheckInterop (~> 10.17)
- FirebaseCore (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- PromisesObjC (~> 2.1)
- FirebaseAppCheckInterop (10.29.0)
- FirebaseCore (10.24.0):
- FirebaseCoreInternal (~> 10.0)
Expand Down Expand Up @@ -2330,6 +2343,10 @@ PODS:
- RNFBApp (19.3.0):
- Firebase/CoreOnly (= 10.24.0)
- React-Core
- RNFBAppCheck (19.3.0):
- Firebase/AppCheck (= 10.24.0)
- React-Core
- RNFBApp
- RNFBCrashlytics (19.3.0):
- Firebase/Crashlytics (= 10.24.0)
- FirebaseCoreExtension
Expand Down Expand Up @@ -2464,6 +2481,7 @@ DEPENDENCIES:
- RNFastImage (from `../node_modules/react-native-fast-image`)
- "RNFBAnalytics (from `../node_modules/@react-native-firebase/analytics`)"
- "RNFBApp (from `../node_modules/@react-native-firebase/app`)"
- "RNFBAppCheck (from `../node_modules/@react-native-firebase/app-check`)"
- "RNFBCrashlytics (from `../node_modules/@react-native-firebase/crashlytics`)"
- "RNFBFirestore (from `../node_modules/@react-native-firebase/firestore`)"
- "RNFBMessaging (from `../node_modules/@react-native-firebase/messaging`)"
Expand All @@ -2480,10 +2498,12 @@ DEPENDENCIES:
SPEC REPOS:
trunk:
- abseil
- AppCheckCore
- BoringSSL-GRPC
- DSFRegex
- Firebase
- FirebaseAnalytics
- FirebaseAppCheck
- FirebaseAppCheckInterop
- FirebaseCore
- FirebaseCoreExtension
Expand Down Expand Up @@ -2649,6 +2669,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/@react-native-firebase/analytics"
RNFBApp:
:path: "../node_modules/@react-native-firebase/app"
RNFBAppCheck:
:path: "../node_modules/@react-native-firebase/app-check"
RNFBCrashlytics:
:path: "../node_modules/@react-native-firebase/crashlytics"
RNFBFirestore:
Expand Down Expand Up @@ -2681,6 +2703,7 @@ CHECKOUT OPTIONS:

SPEC CHECKSUMS:
abseil: d121da9ef7e2ff4cab7666e76c5a3e0915ae08c3
AppCheckCore: 9feb4300caa596a36416cde10674dc5bec1e022e
boost: d3f49c53809116a5d38da093a8aa78bf551aed09
BoringSSL-GRPC: 1e2348957acdbcad360b80a264a90799984b2ba6
BVLinearGradient: 880f91a7854faff2df62518f0281afb1c60d49a3
Expand All @@ -2690,6 +2713,7 @@ SPEC CHECKSUMS:
FBReactNativeSpec: bbe8b686178e5ce03d1d8a356789f211f91f31b8
Firebase: 91fefd38712feb9186ea8996af6cbdef41473442
FirebaseAnalytics: b5efc493eb0f40ec560b04a472e3e1a15d39ca13
FirebaseAppCheck: afb42367002c12bbb5f58c4a954ecd2f0a171182
FirebaseAppCheckInterop: 6a1757cfd4067d8e00fccd14fcc1b8fd78cfac07
FirebaseCore: 11dc8a16dfb7c5e3c3f45ba0e191a33ac4f50894
FirebaseCoreExtension: 705ca5b14bf71d2564a0ddc677df1fc86ffa600f
Expand Down Expand Up @@ -2773,6 +2797,7 @@ SPEC CHECKSUMS:
RNFastImage: 5c9c9fed9c076e521b3f509fe79e790418a544e8
RNFBAnalytics: bb0047a8843d13fc7ecc9fb834fc80e969c1851f
RNFBApp: de81f7eb68c1e6107574f2b102b0dee92a9862fa
RNFBAppCheck: 0b9aa7105e2db741ebd93989662e3a0f5e8d3839
RNFBCrashlytics: 06ccc1939384332a99a9c5f86e76f90154f2caa5
RNFBFirestore: ed29ba9f6fda6341b660d78fd333d39af5641d91
RNFBMessaging: bcceb47d52080700672f4a46aa9096d9754a988f
Expand All @@ -2796,6 +2821,6 @@ SPEC CHECKSUMS:
TinyCSV: fd6228edbcf1c07466ac34b76dac5e052143eaba
Yoga: 428500217b7b2dba1074041bd3ccf0cad3555925

PODFILE CHECKSUM: 7e339a0caa0f5779792bcde7c7a641a4aa47323b
PODFILE CHECKSUM: f6f7c7b9fc5a13b9133fd501db82da96af32da20

COCOAPODS: 1.15.2
3 changes: 3 additions & 0 deletions ios/lrtApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import CarPlay
import Firebase
import GoogleCast
import React
import RNFBAppCheck
import React_RCTAppDelegate
import UIKit

Expand All @@ -23,7 +24,9 @@ class AppDelegate: RCTAppDelegate, GCKLoggerDelegate {
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
RNFBAppCheckModule.sharedInstance()
FirebaseApp.configure()

let kReceiverAppID = kGCKDefaultMediaReceiverApplicationID
let criteria = GCKDiscoveryCriteria(applicationID: kReceiverAppID)
let options = GCKCastOptions(discoveryCriteria: criteria)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@react-native-community/slider": "^4.5.0",
"@react-native-firebase/analytics": "^19.3.0",
"@react-native-firebase/app": "^19.3.0",
"@react-native-firebase/app-check": "^19.3.0",
"@react-native-firebase/crashlytics": "^19.3.0",
"@react-native-firebase/firestore": "^19.3.0",
"@react-native-firebase/messaging": "^19.3.0",
Expand Down

0 comments on commit 8a9c0cf

Please sign in to comment.