Describe the bug
Authentication to a second non default firebase app gets the default auth user object to get overridden.
Steps to reproduce the behavior:
I expected when authenticating through a second instance to get a second auth User instance completely independent from each other.
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:google_sign_in/google_sign_in.dart';
class AuthExample {
AuthExample._();
static FirebaseApp defaultApp;
static FirebaseAuth defaultAuth;
static FirebaseApp secondApp;
static FirebaseAuth secondAuth;
static Future init() async {
defaultApp = await Firebase.initializeApp();
defaultAuth = FirebaseAuth.instance;
secondApp = await Firebase.initializeApp(
name: '[SECOND]',
options: FirebaseOptions(
appId: '1:3xxxxxxxxxxxxxxxxxxxxx',
apiKey: 'Axxxxxxxxxxxxxxxxxxxxxxxxx',
messagingSenderId: 'xxxxxxxxxxx',
projectId: 'xxxxxxxxxxxxxxx',
),
);
secondAuth = FirebaseAuth.instanceFor(app: secondApp);
}
Future<void> signinDefault({bool silent = false}) async {
GoogleSignInAccount googleSignInAccount;
GoogleSignIn googleSignIn = GoogleSignIn(scopes: ['email', 'profile', 'openid']);
if (silent) {
googleSignInAccount = await googleSignIn.signInSilently();
} else {
googleSignInAccount = await googleSignIn.signIn();
}
GoogleSignInAuthentication authentication = await googleSignInAccount.authentication;
GoogleAuthCredential credential =
GoogleAuthProvider.credential(idToken: authentication.idToken, accessToken: authentication.accessToken);
await defaultAuth.signInWithCredential(credential);
print("[DEFAULT] : " + defaultAuth.currentUser.toString());
}
Future<void> signoutDefault() async {
await defaultAuth.signOut();
}
Future<void> signinSecond() async {
await secondAuth.signInWithEmailAndPassword(email: defaultAuth.currentUser.email, password: defaultAuth.currentUser.uid);
print("[DEFAULT] : " + defaultAuth.currentUser.toString());
print('-----------------------------------');
print("[SECOND] : " + secondAuth.currentUser.toString());
//Must re sign in with default auth to recover default User data
await signinDefault(silent: true);
print("[DEFAULT] : " + defaultAuth.currentUser.toString());
print('-----------------------------------');
print("[SECOND] : " + secondAuth.currentUser.toString());
}
Future<void> signoutSecond() async {
await secondAuth.signOut();
await secondApp.delete();
}
}
Run flutter doctor and paste the output below:
Click To Expand
[√] Flutter (Channel stable, 1.20.2, on Microsoft Windows [Version 10.0.19041.508], locale en-US)
• Flutter version 1.20.2 at C:\Flutter
• Framework revision bbfbf1770c (5 weeks ago), 2020-08-13 08:33:09 -0700
• Engine revision 9d5b21729f
• Dart version 2.9.1
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
• Android SDK at C:\Users\Abinn\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.1
• Java binary at: C:\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Android Studio (version 4.0)
• Android Studio at C:\Android Studio
• Flutter plugin version 48.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] Connected device (1 available)
• SM M105G (mobile) • 5200f1e8d4dca669 • android-arm • Android 10 (API 29)
• No issues found!
Run flutter pub deps -- --style=compact and paste the output below:
Click To Expand
- firebase_auth 0.18.0+1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter]
- firebase_core 0.5.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- google_sign_in 4.5.3 [google_sign_in_platform_interface flutter meta google_sign_in_web]
Hi @Ma-Altaiir , please provide a reproducible example, please. Thank you.
Thanks for the sample, @Ma-Altaiir, I was able to reproduce the bug 👍 . Quick tip though, it was only by luck that I noticed you'd updated your initial comment. I recommend writing a new comment so that other posters interested in the discussion are notified 👌 .
Most helpful comment
Thanks for the sample, @Ma-Altaiir, I was able to reproduce the bug 👍 . Quick tip though, it was only by luck that I noticed you'd updated your initial comment. I recommend writing a new comment so that other posters interested in the discussion are notified 👌 .