I tried to follow the solution here, Flutter: Firebase authentication create user without logging In,
Future<void> register(BuildContext context) async {
FirebaseApp app = await Firebase.initializeApp(
name: 'secondary', options: Firebase.app().options);
try {
UserCredential userCredential = await FirebaseAuth.instanceFor(app: app)
.createUserWithEmailAndPassword(
email: email.text, password: password.text);
Navigator.push(
context,
MaterialPageRoute(builder: (context) => createSetupPage()),
);
} on FirebaseAuthException catch (e) {
if (e.code == 'weak-password') {
setState(() {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('Weak Password'),
));
});
} else if (e.code == 'email-already-in-use') {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('Email Already In Use'),
));
}
} catch (e) {
print(e);
}
}
When I create an account, it works once then gives me this error when I try using this code to make another account with the same name, it gives me this error in the console
E/flutter ( 1191): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: [core/duplicate-app] A Firebase App named "secondary" already exists
How do I fix this so that I can keep making multiple accounts without getting logged out from one account? It seems that I need a new name every in the Firebase.initialize app part.