Last active
January 30, 2024 22:33
-
-
Save brokeyourbike/33ef16bfeba6b28734609acde57d891e to your computer and use it in GitHub Desktop.
Flutter Auth Experiments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:firebase_core/firebase_core.dart'; | |
import 'package:firebase_app_check/firebase_app_check.dart'; | |
Future<void> main() async { | |
WidgetsFlutterBinding.ensureInitialized(); | |
await Firebase.initializeApp(); | |
await FirebaseAppCheck.instance.activate( | |
// Default provider for Android is the Play Integrity provider. You can use the "AndroidProvider" enum to choose | |
// your preferred provider. Choose from: | |
// 1. Debug provider | |
// 2. Safety Net provider | |
// 3. Play Integrity provider | |
androidProvider: AndroidProvider.debug, | |
); | |
} | |
try { | |
User? auth = FirebaseAuth.instance.currentUser; | |
if(provider.password.text.isEmpty || provider.email.text.isEmpty){ | |
reAuthenticationDialogBox(context: context); | |
} else if(auth != null){ | |
await FirebaseAuth.instance.signInWithEmailAndPassword( | |
email: provider.email.text, | |
password: provider.password.text, | |
); | |
}else{ | |
reAuthenticationDialogBox(context: context); | |
} | |
} on FirebaseAuthMultiFactorException catch (e) { | |
final session = e.resolver.session; | |
final hint = e.resolver.hints.first; | |
await FirebaseAuth.instance.verifyPhoneNumber( | |
multiFactorSession: session, | |
multiFactorInfo: hint, | |
verificationCompleted: (_) {}, | |
verificationFailed: (e) { | |
print("verification Failed $e"); | |
}, | |
codeSent: (String verificationId, int? resendToken) async {}, | |
codeAutoRetrievalTimeout: (_) {}, | |
timeout: Duration(seconds: 120), | |
); | |
} catch (e) { | |
print("Catch $e"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment