getFirebaseUser method
Implementation
Future<UserCredential> getFirebaseUser() async {
UserCredential? userCredential;
try {
/// login with Firebase
userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(email: appStore.userEmail, password: DEFAULT_FIREBASE_PASSWORD);
} on FirebaseAuthException catch (e) {
if (e.code == 'user-not-found') {
/// register user in Firebase
userCredential = await FirebaseAuth.instance.createUserWithEmailAndPassword(email: appStore.userEmail, password: DEFAULT_FIREBASE_PASSWORD);
}
}
if (userCredential != null && userCredential.user == null) {
userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(email: appStore.userEmail, password: DEFAULT_FIREBASE_PASSWORD);
}
if (userCredential != null) {
return userCredential;
} else {
throw errorSomethingWentWrong;
}
}