Skip to content

Commit

Permalink
Init Firebase AppCheck in Dart
Browse files Browse the repository at this point in the history
  • Loading branch information
anhappdev committed May 28, 2024
1 parent fdec388 commit c75b55b
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions flutter/lib/firebase/firebase_manager.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'dart:convert';

import 'package:flutter/foundation.dart';

import 'package:firebase_app_check/firebase_app_check.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
Expand Down Expand Up @@ -34,14 +37,32 @@ class FirebaseManager {
}
final currentPlatform = DefaultFirebaseOptions.currentPlatform;
final app = await Firebase.initializeApp(options: currentPlatform);
print('Firebase initialized using projectId: ${app.options.projectId}');

// _initAppCheck() must run before any Firebase services,
// but after calling Firebase.initializeApp();
await _initAppCheck();
await _initAuthentication();
_initStorage();
_isInitialized = true;
print('Firebase initialized using projectId: ${app.options.projectId}');
return instance;
}

Future<void> _initAppCheck() async {
if (kReleaseMode) {
await FirebaseAppCheck.instance.activate(
androidProvider: AndroidProvider.playIntegrity,
appleProvider: AppleProvider.deviceCheck,
);
print('Init Firebase App Check in release mode');
} else {
await FirebaseAppCheck.instance.activate(
androidProvider: AndroidProvider.debug,
appleProvider: AppleProvider.debug,
);
print('Init Firebase App Check in debug mode');
}
}

Future<void> _initAuthentication() async {
FirebaseUIAuth.configureProviders(FirebaseAuthService.providers);
_authService.firebaseAuth = FirebaseAuth.instance;
Expand Down

0 comments on commit c75b55b

Please sign in to comment.