diff --git a/packages/firebase_auth/README.md b/packages/firebase_auth/README.md index 2a2d577c1758..ea654cc74a07 100755 --- a/packages/firebase_auth/README.md +++ b/packages/firebase_auth/README.md @@ -55,7 +55,7 @@ import 'package:firebase_auth/firebase_auth.dart'; Initialize `GoogleSignIn` and `FirebaseAuth`: ```dart final GoogleSignIn _googleSignIn = GoogleSignIn(); -final FirebaseAuth _auth = FirebaseAuth(); +final FirebaseAuth _auth = FirebaseAuth.instance; ``` You can now use the Firebase `_auth` to authenticate in your Dart code, e.g. diff --git a/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java b/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java index b9e936c69151..dd932794a139 100755 --- a/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java +++ b/packages/firebase_auth/android/src/main/java/io/flutter/plugins/firebaseauth/FirebaseAuthPlugin.java @@ -29,6 +29,7 @@ /** Flutter plugin for Firebase Auth. */ public class FirebaseAuthPlugin implements MethodCallHandler { private final PluginRegistry.Registrar registrar; + private final FirebaseAuth firebaseAuth; private final SparseArray authStateListeners = new SparseArray<>(); private final SparseArray forceResendingTokens = @@ -50,98 +51,92 @@ private FirebaseAuthPlugin(PluginRegistry.Registrar registrar, MethodChannel cha this.registrar = registrar; this.channel = channel; FirebaseApp.initializeApp(registrar.context()); - } - - private FirebaseAuth getAuth(MethodCall call) { - Map arguments = (Map) call.arguments; - String appName = (String) arguments.get("app"); - FirebaseApp app = FirebaseApp.getInstance(appName); - return FirebaseAuth.getInstance(app); + this.firebaseAuth = FirebaseAuth.getInstance(); } @Override public void onMethodCall(MethodCall call, Result result) { switch (call.method) { case "currentUser": - handleCurrentUser(call, result, getAuth(call)); + handleCurrentUser(call, result); break; case "signInAnonymously": - handleSignInAnonymously(call, result, getAuth(call)); + handleSignInAnonymously(call, result); break; case "createUserWithEmailAndPassword": - handleCreateUserWithEmailAndPassword(call, result, getAuth(call)); + handleCreateUserWithEmailAndPassword(call, result); break; case "fetchProvidersForEmail": - handleFetchProvidersForEmail(call, result, getAuth(call)); + handleFetchProvidersForEmail(call, result); break; case "sendPasswordResetEmail": - handleSendPasswordResetEmail(call, result, getAuth(call)); + handleSendPasswordResetEmail(call, result); break; case "sendEmailVerification": - handleSendEmailVerification(call, result, getAuth(call)); + handleSendEmailVerification(call, result); break; case "reload": - handleReload(call, result, getAuth(call)); + handleReload(call, result); break; case "delete": - handleDelete(call, result, getAuth(call)); + handleDelete(call, result); break; case "signInWithEmailAndPassword": - handleSignInWithEmailAndPassword(call, result, getAuth(call)); + handleSignInWithEmailAndPassword(call, result); break; case "signInWithGoogle": - handleSignInWithGoogle(call, result, getAuth(call)); + handleSignInWithGoogle(call, result); break; case "signInWithCustomToken": - handleSignInWithCustomToken(call, result, getAuth(call)); + handleSignInWithCustomToken(call, result); break; case "signInWithFacebook": - handleSignInWithFacebook(call, result, getAuth(call)); + handleSignInWithFacebook(call, result); break; case "signInWithTwitter": - handleSignInWithTwitter(call, result, getAuth(call)); + handleSignInWithTwitter(call, result); break; case "signOut": - handleSignOut(call, result, getAuth(call)); + handleSignOut(call, result); break; case "getIdToken": - handleGetToken(call, result, getAuth(call)); + handleGetToken(call, result); break; case "linkWithEmailAndPassword": - handleLinkWithEmailAndPassword(call, result, getAuth(call)); + handleLinkWithEmailAndPassword(call, result); break; case "linkWithGoogleCredential": - handleLinkWithGoogleCredential(call, result, getAuth(call)); + handleLinkWithGoogleCredential(call, result); break; case "linkWithFacebookCredential": - handleLinkWithFacebookCredential(call, result, getAuth(call)); + handleLinkWithFacebookCredential(call, result); break; case "linkWithTwitterCredential": - handleLinkWithTwitterCredential(call, result, getAuth(call)); + handleLinkWithTwitterCredential(call, result); break; case "updateEmail": - handleUpdateEmail(call, result, getAuth(call)); + handleUpdateEmail(call, result); break; case "updatePassword": - handleUpdatePassword(call, result, getAuth(call)); + handleUpdatePassword(call, result); break; case "updateProfile": - handleUpdateProfile(call, result, getAuth(call)); + handleUpdateProfile(call, result); break; case "startListeningAuthState": - handleStartListeningAuthState(call, result, getAuth(call)); + handleStartListeningAuthState(call, result); break; case "stopListeningAuthState": - handleStopListeningAuthState(call, result, getAuth(call)); + handleStopListeningAuthState(call, result); break; case "verifyPhoneNumber": - handleVerifyPhoneNumber(call, result, getAuth(call)); + handleVerifyPhoneNumber(call, result); break; case "signInWithPhoneNumber": - handleSignInWithPhoneNumber(call, result, getAuth(call)); + handleSignInWithPhoneNumber(call, result); break; case "setLanguageCode": - handleSetLanguageCode(call, result, getAuth(call)); + handleSetLanguageCode(call, result); break; default: result.notImplemented(); @@ -149,8 +144,7 @@ public void onMethodCall(MethodCall call, Result result) { } } - private void handleSignInWithPhoneNumber( - MethodCall call, Result result, FirebaseAuth firebaseAuth) { + private void handleSignInWithPhoneNumber(MethodCall call, Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; String verificationId = arguments.get("verificationId"); @@ -163,8 +157,7 @@ private void handleSignInWithPhoneNumber( .addOnCompleteListener(new SignInCompleteListener(result)); } - private void handleVerifyPhoneNumber( - MethodCall call, Result result, final FirebaseAuth firebaseAuth) { + private void handleVerifyPhoneNumber(MethodCall call, Result result) { @SuppressWarnings("unchecked") final int handle = call.argument("handle"); String phoneNumber = call.argument("phoneNumber"); @@ -257,8 +250,7 @@ private Map getVerifyPhoneNumberExceptionMap(FirebaseException e return exceptionMap; } - private void handleLinkWithEmailAndPassword( - MethodCall call, Result result, FirebaseAuth firebaseAuth) { + private void handleLinkWithEmailAndPassword(MethodCall call, Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; String email = arguments.get("email"); @@ -271,23 +263,26 @@ private void handleLinkWithEmailAndPassword( .addOnCompleteListener(new SignInCompleteListener(result)); } - private void handleCurrentUser(MethodCall call, final Result result, FirebaseAuth firebaseAuth) { - FirebaseUser user = firebaseAuth.getCurrentUser(); - if (user == null) { - result.success(null); - return; - } - Map userMap = mapFromUser(user); - result.success(userMap); + private void handleCurrentUser(MethodCall call, final Result result) { + final FirebaseAuth.AuthStateListener listener = + new FirebaseAuth.AuthStateListener() { + @Override + public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { + firebaseAuth.removeAuthStateListener(this); + FirebaseUser user = firebaseAuth.getCurrentUser(); + Map userMap = mapFromUser(user); + result.success(userMap); + } + }; + + firebaseAuth.addAuthStateListener(listener); } - private void handleSignInAnonymously( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleSignInAnonymously(MethodCall call, final Result result) { firebaseAuth.signInAnonymously().addOnCompleteListener(new SignInCompleteListener(result)); } - private void handleCreateUserWithEmailAndPassword( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleCreateUserWithEmailAndPassword(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; String email = arguments.get("email"); @@ -298,8 +293,7 @@ private void handleCreateUserWithEmailAndPassword( .addOnCompleteListener(new SignInCompleteListener(result)); } - private void handleFetchProvidersForEmail( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleFetchProvidersForEmail(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; String email = arguments.get("email"); @@ -309,8 +303,7 @@ private void handleFetchProvidersForEmail( .addOnCompleteListener(new ProvidersCompleteListener(result)); } - private void handleSendPasswordResetEmail( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleSendPasswordResetEmail(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; String email = arguments.get("email"); @@ -320,23 +313,28 @@ private void handleSendPasswordResetEmail( .addOnCompleteListener(new TaskVoidCompleteListener(result)); } - private void handleSendEmailVerification( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleSendEmailVerification(MethodCall call, final Result result) { firebaseAuth .getCurrentUser() .sendEmailVerification() .addOnCompleteListener(new TaskVoidCompleteListener(result)); } - private void handleReload(MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleReload(MethodCall call, final Result result) { firebaseAuth .getCurrentUser() .reload() .addOnCompleteListener(new TaskVoidCompleteListener(result)); } - private void handleSignInWithEmailAndPassword( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleDelete(MethodCall call, final Result result) { + firebaseAuth + .getCurrentUser() + .delete() + .addOnCompleteListener(new TaskVoidCompleteListener(result)); + } + + private void handleSignInWithEmailAndPassword(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; String email = arguments.get("email"); @@ -347,15 +345,7 @@ private void handleSignInWithEmailAndPassword( .addOnCompleteListener(new SignInCompleteListener(result)); } - private void handleDelete(MethodCall call, final Result result, FirebaseAuth firebaseAuth) { - firebaseAuth - .getCurrentUser() - .delete() - .addOnCompleteListener(new TaskVoidCompleteListener(result)); - } - - private void handleSignInWithGoogle( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleSignInWithGoogle(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; String idToken = arguments.get("idToken"); @@ -366,8 +356,7 @@ private void handleSignInWithGoogle( .addOnCompleteListener(new SignInCompleteListener(result)); } - private void handleLinkWithGoogleCredential( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleLinkWithGoogleCredential(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; String idToken = arguments.get("idToken"); @@ -379,8 +368,7 @@ private void handleLinkWithGoogleCredential( .addOnCompleteListener(new SignInCompleteListener(result)); } - private void handleLinkWithFacebookCredential( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleLinkWithFacebookCredential(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; String accessToken = arguments.get("accessToken"); @@ -391,8 +379,7 @@ private void handleLinkWithFacebookCredential( .addOnCompleteListener(new SignInCompleteListener(result)); } - private void handleLinkWithTwitterCredential( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleLinkWithTwitterCredential(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; String authToken = arguments.get("authToken"); @@ -404,8 +391,7 @@ private void handleLinkWithTwitterCredential( .addOnCompleteListener(new SignInCompleteListener(result)); } - private void handleSignInWithFacebook( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleSignInWithFacebook(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; String accessToken = arguments.get("accessToken"); @@ -415,8 +401,7 @@ private void handleSignInWithFacebook( .addOnCompleteListener(new SignInCompleteListener(result)); } - private void handleSignInWithTwitter( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleSignInWithTwitter(MethodCall call, final Result result) { String authToken = call.argument("authToken"); String authTokenSecret = call.argument("authTokenSecret"); AuthCredential credential = TwitterAuthProvider.getCredential(authToken, authTokenSecret); @@ -425,8 +410,7 @@ private void handleSignInWithTwitter( .addOnCompleteListener(new SignInCompleteListener(result)); } - private void handleSignInWithCustomToken( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleSignInWithCustomToken(MethodCall call, final Result result) { Map arguments = call.arguments(); String token = arguments.get("token"); firebaseAuth @@ -434,12 +418,12 @@ private void handleSignInWithCustomToken( .addOnCompleteListener(new SignInCompleteListener(result)); } - private void handleSignOut(MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleSignOut(MethodCall call, final Result result) { firebaseAuth.signOut(); result.success(null); } - private void handleGetToken(MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleGetToken(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; boolean refresh = arguments.get("refresh"); @@ -459,7 +443,7 @@ public void onComplete(@NonNull Task task) { }); } - private void handleUpdateEmail(MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleUpdateEmail(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; firebaseAuth @@ -468,8 +452,7 @@ private void handleUpdateEmail(MethodCall call, final Result result, FirebaseAut .addOnCompleteListener(new TaskVoidCompleteListener(result)); } - private void handleUpdatePassword( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleUpdatePassword(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; firebaseAuth @@ -478,8 +461,7 @@ private void handleUpdatePassword( .addOnCompleteListener(new TaskVoidCompleteListener(result)); } - private void handleUpdateProfile( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleUpdateProfile(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; @@ -497,8 +479,7 @@ private void handleUpdateProfile( .addOnCompleteListener(new TaskVoidCompleteListener(result)); } - private void handleStartListeningAuthState( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleStartListeningAuthState(MethodCall call, final Result result) { final int handle = nextHandle++; FirebaseAuth.AuthStateListener listener = new FirebaseAuth.AuthStateListener() { @@ -515,19 +496,18 @@ public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { channel.invokeMethod("onAuthStateChanged", Collections.unmodifiableMap(map)); } }; - firebaseAuth.addAuthStateListener(listener); + FirebaseAuth.getInstance().addAuthStateListener(listener); authStateListeners.append(handle, listener); result.success(handle); } - private void handleStopListeningAuthState( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleStopListeningAuthState(MethodCall call, final Result result) { Map arguments = call.arguments(); Integer id = arguments.get("id"); FirebaseAuth.AuthStateListener listener = authStateListeners.get(id); if (listener != null) { - firebaseAuth.removeAuthStateListener(listener); + FirebaseAuth.getInstance().removeAuthStateListener(listener); authStateListeners.remove(id); result.success(null); } else { @@ -538,8 +518,7 @@ private void handleStopListeningAuthState( } } - private void handleSetLanguageCode( - MethodCall call, final Result result, FirebaseAuth firebaseAuth) { + private void handleSetLanguageCode(MethodCall call, final Result result) { @SuppressWarnings("unchecked") Map arguments = (Map) call.arguments; String language = arguments.get("language"); diff --git a/packages/firebase_auth/example/ios/Runner.xcodeproj/project.pbxproj b/packages/firebase_auth/example/ios/Runner.xcodeproj/project.pbxproj old mode 100644 new mode 100755 index db497a45aa5b..eebc126be7ae --- a/packages/firebase_auth/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/firebase_auth/example/ios/Runner.xcodeproj/project.pbxproj @@ -8,8 +8,8 @@ /* Begin PBXBuildFile section */ 0690AA46E879ED4CF7B7AEB4 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A6A0D603F1BEC33B95572EC3 /* libPods-Runner.a */; }; - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 5C97AA501EC3F2C300D441D1 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 5C97AA4F1EC3F2C300D441D1 /* GeneratedPluginRegistrant.m */; }; @@ -41,8 +41,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 5C97AA4E1EC3F2C300D441D1 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 5C97AA4F1EC3F2C300D441D1 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; @@ -253,8 +253,7 @@ ); name = "[CP] Copy Pods Resources"; outputPaths = ( - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GTMOAuth2ViewTouch.nib", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GoogleSignIn.bundle", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -268,7 +267,7 @@ ); inputPaths = ( "${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", - "${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework", + "${PODS_ROOT}/../../../../../../../flutter/bin/cache/artifacts/engine/ios/Flutter.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( diff --git a/packages/firebase_auth/example/lib/main.dart b/packages/firebase_auth/example/lib/main.dart index bc103e2de85e..2dce1c78b61a 100755 --- a/packages/firebase_auth/example/lib/main.dart +++ b/packages/firebase_auth/example/lib/main.dart @@ -9,7 +9,7 @@ import 'package:flutter/material.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:google_sign_in/google_sign_in.dart'; -final FirebaseAuth _auth = FirebaseAuth(); +final FirebaseAuth _auth = FirebaseAuth.instance; final GoogleSignIn _googleSignIn = GoogleSignIn(); void main() { diff --git a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m index e45ee9ad3c71..5bdf4b929992 100644 --- a/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m +++ b/packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m @@ -59,20 +59,15 @@ - (instancetype)init { return self; } -- (FIRAuth *_Nullable)getAuth:(NSDictionary *)args { - NSString *appName = [args objectForKey:@"app"]; - return [FIRAuth authWithApp:[FIRApp appNamed:appName]]; -} - - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { if ([@"currentUser" isEqualToString:call.method]) { - id __block listener = [[self getAuth:call.arguments] + id __block listener = [[FIRAuth auth] addAuthStateDidChangeListener:^(FIRAuth *_Nonnull auth, FIRUser *_Nullable user) { [self sendResult:result forUser:user error:nil]; [auth removeAuthStateDidChangeListener:listener]; }]; } else if ([@"signInAnonymously" isEqualToString:call.method]) { - [[self getAuth:call.arguments] + [[FIRAuth auth] signInAnonymouslyWithCompletion:^(FIRAuthDataResult *dataResult, NSError *error) { [self sendResult:result forUser:dataResult.user error:error]; }]; @@ -81,74 +76,69 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result NSString *accessToken = call.arguments[@"accessToken"]; FIRAuthCredential *credential = [FIRGoogleAuthProvider credentialWithIDToken:idToken accessToken:accessToken]; - [[self getAuth:call.arguments] signInWithCredential:credential - completion:^(FIRUser *user, NSError *error) { - [self sendResult:result forUser:user error:error]; - }]; + [[FIRAuth auth] signInWithCredential:credential + completion:^(FIRUser *user, NSError *error) { + [self sendResult:result forUser:user error:error]; + }]; } else if ([@"signInWithFacebook" isEqualToString:call.method]) { NSString *accessToken = call.arguments[@"accessToken"]; FIRAuthCredential *credential = [FIRFacebookAuthProvider credentialWithAccessToken:accessToken]; - [[self getAuth:call.arguments] signInWithCredential:credential - completion:^(FIRUser *user, NSError *error) { - [self sendResult:result forUser:user error:error]; - }]; + [[FIRAuth auth] signInWithCredential:credential + completion:^(FIRUser *user, NSError *error) { + [self sendResult:result forUser:user error:error]; + }]; } else if ([@"signInWithTwitter" isEqualToString:call.method]) { NSString *authToken = call.arguments[@"authToken"]; NSString *authTokenSecret = call.arguments[@"authTokenSecret"]; FIRAuthCredential *credential = [FIRTwitterAuthProvider credentialWithToken:authToken secret:authTokenSecret]; - [[self getAuth:call.arguments] signInWithCredential:credential - completion:^(FIRUser *user, NSError *error) { - [self sendResult:result forUser:user error:error]; - }]; + [[FIRAuth auth] signInWithCredential:credential + completion:^(FIRUser *user, NSError *error) { + [self sendResult:result forUser:user error:error]; + }]; } else if ([@"createUserWithEmailAndPassword" isEqualToString:call.method]) { NSString *email = call.arguments[@"email"]; NSString *password = call.arguments[@"password"]; - [[self getAuth:call.arguments] - createUserWithEmail:email - password:password - completion:^(FIRAuthDataResult *dataResult, NSError *error) { - [self sendResult:result forUser:dataResult.user error:error]; - }]; + [[FIRAuth auth] createUserWithEmail:email + password:password + completion:^(FIRAuthDataResult *dataResult, NSError *error) { + [self sendResult:result forUser:dataResult.user error:error]; + }]; } else if ([@"fetchProvidersForEmail" isEqualToString:call.method]) { NSString *email = call.arguments[@"email"]; - [[self getAuth:call.arguments] - fetchProvidersForEmail:email - completion:^(NSArray *providers, NSError *error) { - [self sendResult:result forProviders:providers error:error]; - }]; + [[FIRAuth auth] fetchProvidersForEmail:email + completion:^(NSArray *providers, NSError *error) { + [self sendResult:result forProviders:providers error:error]; + }]; } else if ([@"sendEmailVerification" isEqualToString:call.method]) { - [[self getAuth:call.arguments].currentUser - sendEmailVerificationWithCompletion:^(NSError *_Nullable error) { - [self sendResult:result forProviders:nil error:error]; - }]; + [[FIRAuth auth].currentUser sendEmailVerificationWithCompletion:^(NSError *_Nullable error) { + [self sendResult:result forProviders:nil error:error]; + }]; } else if ([@"reload" isEqualToString:call.method]) { - [[self getAuth:call.arguments].currentUser reloadWithCompletion:^(NSError *_Nullable error) { + [[FIRAuth auth].currentUser reloadWithCompletion:^(NSError *_Nullable error) { [self sendResult:result forProviders:nil error:error]; }]; } else if ([@"delete" isEqualToString:call.method]) { - [[self getAuth:call.arguments].currentUser deleteWithCompletion:^(NSError *_Nullable error) { + [[FIRAuth auth].currentUser deleteWithCompletion:^(NSError *_Nullable error) { [self sendResult:result forProviders:nil error:error]; }]; } else if ([@"sendPasswordResetEmail" isEqualToString:call.method]) { NSString *email = call.arguments[@"email"]; - [[self getAuth:call.arguments] - sendPasswordResetWithEmail:email - completion:^(NSError *error) { - [self sendResult:result forUser:nil error:error]; - }]; + [[FIRAuth auth] sendPasswordResetWithEmail:email + completion:^(NSError *error) { + [self sendResult:result forUser:nil error:error]; + }]; } else if ([@"signInWithEmailAndPassword" isEqualToString:call.method]) { NSString *email = call.arguments[@"email"]; NSString *password = call.arguments[@"password"]; - [[self getAuth:call.arguments] - signInWithEmail:email - password:password - completion:^(FIRAuthDataResult *dataResult, NSError *error) { - [self sendResult:result forUser:dataResult.user error:error]; - }]; + [[FIRAuth auth] signInWithEmail:email + password:password + completion:^(FIRAuthDataResult *dataResult, NSError *error) { + [self sendResult:result forUser:dataResult.user error:error]; + }]; } else if ([@"signOut" isEqualToString:call.method]) { NSError *signOutError; - BOOL status = [[self getAuth:call.arguments] signOut:&signOutError]; + BOOL status = [[FIRAuth auth] signOut:&signOutError]; if (!status) { NSLog(@"Error signing out: %@", signOutError); [self sendResult:result forUser:nil error:signOutError]; @@ -156,7 +146,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [self sendResult:result forUser:nil error:nil]; } } else if ([@"getIdToken" isEqualToString:call.method]) { - [[self getAuth:call.arguments].currentUser + [[FIRAuth auth].currentUser getIDTokenForcingRefresh:YES completion:^(NSString *_Nullable token, NSError *_Nullable error) { result(error != nil ? error.flutterError : token); @@ -166,55 +156,50 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result NSString *password = call.arguments[@"password"]; FIRAuthCredential *credential = [FIREmailAuthProvider credentialWithEmail:email password:password]; - [[self getAuth:call.arguments].currentUser - linkWithCredential:credential - completion:^(FIRUser *user, NSError *error) { - [self sendResult:result forUser:user error:error]; - }]; + [[FIRAuth auth].currentUser linkWithCredential:credential + completion:^(FIRUser *user, NSError *error) { + [self sendResult:result forUser:user error:error]; + }]; } else if ([@"linkWithGoogleCredential" isEqualToString:call.method]) { NSString *idToken = call.arguments[@"idToken"]; NSString *accessToken = call.arguments[@"accessToken"]; FIRAuthCredential *credential = [FIRGoogleAuthProvider credentialWithIDToken:idToken accessToken:accessToken]; - [[self getAuth:call.arguments].currentUser - linkWithCredential:credential - completion:^(FIRUser *user, NSError *error) { - [self sendResult:result forUser:user error:error]; - }]; + [[FIRAuth auth].currentUser linkWithCredential:credential + completion:^(FIRUser *user, NSError *error) { + [self sendResult:result forUser:user error:error]; + }]; } else if ([@"linkWithFacebookCredential" isEqualToString:call.method]) { NSString *accessToken = call.arguments[@"accessToken"]; FIRAuthCredential *credential = [FIRFacebookAuthProvider credentialWithAccessToken:accessToken]; - [[self getAuth:call.arguments].currentUser - linkWithCredential:credential - completion:^(FIRUser *user, NSError *error) { - [self sendResult:result forUser:user error:error]; - }]; + [[FIRAuth auth].currentUser linkWithCredential:credential + completion:^(FIRUser *user, NSError *error) { + [self sendResult:result forUser:user error:error]; + }]; } else if ([@"linkWithTwitterCredential" isEqualToString:call.method]) { NSString *authToken = call.arguments[@"authToken"]; NSString *authTokenSecret = call.arguments[@"authTokenSecret"]; FIRAuthCredential *credential = [FIRTwitterAuthProvider credentialWithToken:authToken secret:authTokenSecret]; - [[self getAuth:call.arguments].currentUser - linkWithCredential:credential - completion:^(FIRUser *user, NSError *error) { - [self sendResult:result forUser:user error:error]; - }]; + [[FIRAuth auth].currentUser linkWithCredential:credential + completion:^(FIRUser *user, NSError *error) { + [self sendResult:result forUser:user error:error]; + }]; } else if ([@"updateEmail" isEqualToString:call.method]) { NSString *email = call.arguments[@"email"]; - [[self getAuth:call.arguments].currentUser updateEmail:email - completion:^(NSError *error) { - [self sendResult:result forUser:nil error:error]; - }]; + [[FIRAuth auth].currentUser updateEmail:email + completion:^(NSError *error) { + [self sendResult:result forUser:nil error:error]; + }]; } else if ([@"updatePassword" isEqualToString:call.method]) { NSString *password = call.arguments[@"password"]; - [[self getAuth:call.arguments].currentUser - updatePassword:password - completion:^(NSError *error) { - [self sendResult:result forUser:nil error:error]; - }]; + [[FIRAuth auth].currentUser updatePassword:password + completion:^(NSError *error) { + [self sendResult:result forUser:nil error:error]; + }]; + } else if ([@"updateProfile" isEqualToString:call.method]) { - FIRUserProfileChangeRequest *changeRequest = - [[self getAuth:call.arguments].currentUser profileChangeRequest]; + FIRUserProfileChangeRequest *changeRequest = [[FIRAuth auth].currentUser profileChangeRequest]; if (call.arguments[@"displayName"]) { changeRequest.displayName = call.arguments[@"displayName"]; } @@ -224,24 +209,17 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [changeRequest commitChangesWithCompletion:^(NSError *error) { [self sendResult:result forUser:nil error:error]; }]; - } else if ([@"updateEmail" isEqualToString:call.method]) { - NSString *toEmail = call.arguments[@"email"]; - [[self getAuth:call.arguments].currentUser updateEmail:toEmail - completion:^(NSError *_Nullable error) { - [self sendResult:result forUser:nil error:error]; - }]; } else if ([@"signInWithCustomToken" isEqualToString:call.method]) { NSString *token = call.arguments[@"token"]; - [[self getAuth:call.arguments] - signInWithCustomToken:token - completion:^(FIRAuthDataResult *dataResult, NSError *error) { - [self sendResult:result forUser:dataResult.user error:error]; - }]; + [[FIRAuth auth] signInWithCustomToken:token + completion:^(FIRAuthDataResult *dataResult, NSError *error) { + [self sendResult:result forUser:dataResult.user error:error]; + }]; } else if ([@"startListeningAuthState" isEqualToString:call.method]) { NSNumber *identifier = [NSNumber numberWithInteger:nextHandle++]; - FIRAuthStateDidChangeListenerHandle listener = [[self getAuth:call.arguments] + FIRAuthStateDidChangeListenerHandle listener = [[FIRAuth auth] addAuthStateDidChangeListener:^(FIRAuth *_Nonnull auth, FIRUser *_Nullable user) { NSMutableDictionary *response = [[NSMutableDictionary alloc] init]; response[@"id"] = identifier; @@ -258,8 +236,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result FIRAuthStateDidChangeListenerHandle listener = self.authStateChangeListeners[identifier]; if (listener) { - [[self getAuth:call.arguments] - removeAuthStateDidChangeListener:self.authStateChangeListeners]; + [[FIRAuth auth] removeAuthStateDidChangeListener:self.authStateChangeListeners]; [self.authStateChangeListeners removeObjectForKey:identifier]; result(nil); } else { @@ -295,13 +272,13 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result FIRPhoneAuthCredential *credential = [[FIRPhoneAuthProvider provider] credentialWithVerificationID:verificationId verificationCode:smsCode]; - [[self getAuth:call.arguments] signInWithCredential:credential - completion:^(FIRUser *user, NSError *error) { - [self sendResult:result forUser:user error:error]; - }]; + [[FIRAuth auth] signInWithCredential:credential + completion:^(FIRUser *user, NSError *error) { + [self sendResult:result forUser:user error:error]; + }]; } else if ([@"setLanguageCode" isEqualToString:call.method]) { NSString *language = call.arguments[@"language"]; - [[self getAuth:call.arguments] setLanguageCode:language]; + [[FIRAuth auth] setLanguageCode:language]; [self sendResult:result forUser:nil error:nil]; } else { result(FlutterMethodNotImplemented); diff --git a/packages/firebase_auth/lib/firebase_auth.dart b/packages/firebase_auth/lib/firebase_auth.dart index 25c1c7899b6b..45a177331b91 100755 --- a/packages/firebase_auth/lib/firebase_auth.dart +++ b/packages/firebase_auth/lib/firebase_auth.dart @@ -6,7 +6,6 @@ import 'dart:async'; import 'package:flutter/services.dart'; import 'package:meta/meta.dart'; -import 'package:firebase_core/firebase_core.dart'; /// Represents user data returned from an identity provider. @@ -20,9 +19,7 @@ class FirebaseUserMetadata { } class UserInfo { - UserInfo._(this._data, this.app); - - FirebaseApp app; + UserInfo._(this._data); final Map _data; @@ -69,12 +66,12 @@ class UserUpdateInfo { /// Represents a user. class FirebaseUser extends UserInfo { - FirebaseUser._(Map data, FirebaseApp app) + FirebaseUser._(Map data) : providerData = data['providerData'] - .map((dynamic item) => UserInfo._(item, app)) + .map((dynamic item) => UserInfo._(item)) .toList(), _metadata = FirebaseUserMetadata._(data), - super._(data, app); + super._(data); final List providerData; final FirebaseUserMetadata _metadata; @@ -93,28 +90,23 @@ class FirebaseUser extends UserInfo { /// /// Completes with an error if the user is signed out. Future getIdToken({bool refresh = false}) async { - return await FirebaseAuth.channel - .invokeMethod('getIdToken', { + return await FirebaseAuth.channel.invokeMethod('getIdToken', { 'refresh': refresh, - 'app': app.name, }); } Future sendEmailVerification() async { - await FirebaseAuth.channel.invokeMethod( - 'sendEmailVerification', {'app': app.name}); + await FirebaseAuth.channel.invokeMethod('sendEmailVerification'); } /// Manually refreshes the data of the current user (for example, attached providers, display name, and so on). Future reload() async { - await FirebaseAuth.channel - .invokeMethod('reload', {'app': app.name}); + await FirebaseAuth.channel.invokeMethod('reload'); } /// Deletes the user record from your Firebase project's database. Future delete() async { - await FirebaseAuth.channel - .invokeMethod('delete', {'app': app.name}); + await FirebaseAuth.channel.invokeMethod('delete'); } /// Updates the email address of the user. @@ -122,7 +114,7 @@ class FirebaseUser extends UserInfo { assert(email != null); return await FirebaseAuth.channel.invokeMethod( 'updateEmail', - {'email': email, 'app': app.name}, + {'email': email}, ); } @@ -131,18 +123,16 @@ class FirebaseUser extends UserInfo { assert(password != null); return await FirebaseAuth.channel.invokeMethod( 'updatePassword', - {'password': password, 'app': app.name}, + {'password': password}, ); } /// Updates the user profile information. Future updateProfile(UserUpdateInfo userUpdateInfo) async { assert(userUpdateInfo != null); - final Map data = userUpdateInfo._updateData; - data['app'] = app.name; return await FirebaseAuth.channel.invokeMethod( 'updateProfile', - data, + userUpdateInfo._updateData, ); } @@ -165,15 +155,15 @@ typedef void PhoneCodeSent(String verificationId, [int forceResendingToken]); typedef void PhoneCodeAutoRetrievalTimeout(String verificationId); class FirebaseAuth { - FirebaseAuth({FirebaseApp app}) - : app = app != null ? app : FirebaseApp.instance { - channel.setMethodCallHandler(_callHandler); - } - FirebaseAuth._() { channel.setMethodCallHandler(_callHandler); } + /// Provides an instance of this class corresponding to the default app. + /// + /// TODO(jackson): Support for non-default apps. + static FirebaseAuth instance = FirebaseAuth._(); + @visibleForTesting static const MethodChannel channel = MethodChannel( 'plugins.flutter.io/firebase_auth', @@ -186,23 +176,22 @@ class FirebaseAuth { final Map> _phoneAuthCallbacks = >{}; - FirebaseApp app; - /// Receive [FirebaseUser] each time the user signIn or signOut Stream get onAuthStateChanged { Future _handle; StreamController controller; controller = StreamController.broadcast(onListen: () { - _handle = channel.invokeMethod('startListeningAuthState', - {"app": app.name}).then((dynamic v) => v); + _handle = channel + .invokeMethod('startListeningAuthState') + .then((dynamic v) => v); _handle.then((int handle) { _authStateChangedControllers[handle] = controller; }); }, onCancel: () { _handle.then((int handle) async { - await channel.invokeMethod("stopListeningAuthState", - {"id": handle, "app": app.name}); + await channel.invokeMethod( + "stopListeningAuthState", {"id": handle}); _authStateChangedControllers.remove(handle); }); }); @@ -220,9 +209,9 @@ class FirebaseAuth { /// FIRAuthErrorCodeOperationNotAllowed - Indicates that anonymous accounts are not enabled. Enable them in the Auth section of the Firebase console. /// See FIRAuthErrors for a list of error codes that are common to all API methods. Future signInAnonymously() async { - final Map data = await channel - .invokeMethod('signInAnonymously', {"app": app.name}); - final FirebaseUser currentUser = FirebaseUser._(data, app); + final Map data = + await channel.invokeMethod('signInAnonymously'); + final FirebaseUser currentUser = FirebaseUser._(data); return currentUser; } @@ -234,9 +223,12 @@ class FirebaseAuth { assert(password != null); final Map data = await channel.invokeMethod( 'createUserWithEmailAndPassword', - {'email': email, 'password': password, 'app': app.name}, + { + 'email': email, + 'password': password, + }, ); - final FirebaseUser currentUser = FirebaseUser._(data, app); + final FirebaseUser currentUser = FirebaseUser._(data); return currentUser; } @@ -246,7 +238,9 @@ class FirebaseAuth { assert(email != null); final List providers = await channel.invokeMethod( 'fetchProvidersForEmail', - {'email': email, 'app': app.name}, + { + 'email': email, + }, ); return providers?.cast(); } @@ -257,7 +251,9 @@ class FirebaseAuth { assert(email != null); return await channel.invokeMethod( 'sendPasswordResetEmail', - {'email': email, 'app': app.name}, + { + 'email': email, + }, ); } @@ -269,19 +265,23 @@ class FirebaseAuth { assert(password != null); final Map data = await channel.invokeMethod( 'signInWithEmailAndPassword', - {'email': email, 'password': password, 'app': app.name}, + { + 'email': email, + 'password': password, + }, ); - final FirebaseUser currentUser = FirebaseUser._(data, app); + final FirebaseUser currentUser = FirebaseUser._(data); return currentUser; } Future signInWithFacebook( {@required String accessToken}) async { assert(accessToken != null); - final Map data = await channel.invokeMethod( - 'signInWithFacebook', - {'accessToken': accessToken, 'app': app.name}); - final FirebaseUser currentUser = FirebaseUser._(data, app); + final Map data = + await channel.invokeMethod('signInWithFacebook', { + 'accessToken': accessToken, + }); + final FirebaseUser currentUser = FirebaseUser._(data); return currentUser; } @@ -294,13 +294,12 @@ class FirebaseAuth { }) async { assert(authToken != null); assert(authTokenSecret != null); - final Map data = await channel.invokeMethod( - 'signInWithTwitter', { + final Map data = + await channel.invokeMethod('signInWithTwitter', { 'authToken': authToken, 'authTokenSecret': authTokenSecret, - 'app': app.name }); - final FirebaseUser currentUser = FirebaseUser._(data, app); + final FirebaseUser currentUser = FirebaseUser._(data); return currentUser; } @@ -315,10 +314,9 @@ class FirebaseAuth { { 'idToken': idToken, 'accessToken': accessToken, - 'app': app.name }, ); - final FirebaseUser currentUser = FirebaseUser._(data, app); + final FirebaseUser currentUser = FirebaseUser._(data); return currentUser; } @@ -331,10 +329,9 @@ class FirebaseAuth { { 'verificationId': verificationId, 'smsCode': smsCode, - 'app': app.name }, ); - final FirebaseUser currentUser = FirebaseUser._(data, app); + final FirebaseUser currentUser = FirebaseUser._(data); return currentUser; } @@ -361,7 +358,6 @@ class FirebaseAuth { 'phoneNumber': phoneNumber, 'timeout': timeout.inMilliseconds, 'forceResendingToken': forceResendingToken, - 'app': app.name }; await channel.invokeMethod('verifyPhoneNumber', params); @@ -371,23 +367,23 @@ class FirebaseAuth { assert(token != null); final Map data = await channel.invokeMethod( 'signInWithCustomToken', - {'token': token, 'app': app.name}, + { + 'token': token, + }, ); - final FirebaseUser currentUser = FirebaseUser._(data, app); + final FirebaseUser currentUser = FirebaseUser._(data); return currentUser; } Future signOut() async { - return await channel - .invokeMethod("signOut", {'app': app.name}); + return await channel.invokeMethod("signOut"); } /// Asynchronously gets current user, or `null` if there is none. Future currentUser() async { - final Map data = await channel - .invokeMethod("currentUser", {'app': app.name}); - final FirebaseUser currentUser = - data == null ? null : FirebaseUser._(data, app); + final Map data = + await channel.invokeMethod("currentUser"); + final FirebaseUser currentUser = data == null ? null : FirebaseUser._(data); return currentUser; } @@ -405,9 +401,12 @@ class FirebaseAuth { assert(password != null); final Map data = await channel.invokeMethod( 'linkWithEmailAndPassword', - {'email': email, 'password': password, 'app': app.name}, + { + 'email': email, + 'password': password, + }, ); - final FirebaseUser currentUser = FirebaseUser._(data, app); + final FirebaseUser currentUser = FirebaseUser._(data); return currentUser; } @@ -430,10 +429,9 @@ class FirebaseAuth { { 'idToken': idToken, 'accessToken': accessToken, - 'app': app.name }, ); - final FirebaseUser currentUser = FirebaseUser._(data, app); + final FirebaseUser currentUser = FirebaseUser._(data); return currentUser; } @@ -443,9 +441,11 @@ class FirebaseAuth { assert(accessToken != null); final Map data = await channel.invokeMethod( 'linkWithFacebookCredential', - {'accessToken': accessToken, 'app': app.name}, + { + 'accessToken': accessToken, + }, ); - final FirebaseUser currentUser = FirebaseUser._(data, app); + final FirebaseUser currentUser = FirebaseUser._(data); return currentUser; } @@ -456,12 +456,11 @@ class FirebaseAuth { final Map data = await channel.invokeMethod( 'linkWithTwitterCredential', { - 'app': app.name, 'authToken': authToken, 'authTokenSecret': authTokenSecret, }, ); - final FirebaseUser currentUser = FirebaseUser._(data, app); + final FirebaseUser currentUser = FirebaseUser._(data); return currentUser; } @@ -472,7 +471,6 @@ class FirebaseAuth { assert(language != null); await FirebaseAuth.channel.invokeMethod('setLanguageCode', { 'language': language, - 'app': app.name, }); } @@ -522,8 +520,7 @@ class FirebaseAuth { final Map data = call.arguments["user"]; final int id = call.arguments["id"]; - final FirebaseUser currentUser = - data != null ? FirebaseUser._(data, app) : null; + final FirebaseUser currentUser = data != null ? FirebaseUser._(data) : null; _authStateChangedControllers[id].add(currentUser); } } diff --git a/packages/firebase_auth/pubspec.yaml b/packages/firebase_auth/pubspec.yaml index 3f5ff50a108f..528a98f9cbd0 100755 --- a/packages/firebase_auth/pubspec.yaml +++ b/packages/firebase_auth/pubspec.yaml @@ -14,8 +14,6 @@ flutter: dependencies: meta: ^1.0.4 - firebase_core: ^0.2.5+1 - flutter: sdk: flutter @@ -24,6 +22,7 @@ dev_dependencies: test: ^1.3.0 flutter_test: sdk: flutter + firebase_core: ^0.2.5+1 environment: sdk: ">=2.0.0-dev.28.0 <3.0.0" diff --git a/packages/firebase_auth/test/firebase_auth_test.dart b/packages/firebase_auth/test/firebase_auth_test.dart index 7b3b97c7d31f..d5f0e3146ee7 100755 --- a/packages/firebase_auth/test/firebase_auth_test.dart +++ b/packages/firebase_auth/test/firebase_auth_test.dart @@ -5,7 +5,6 @@ import 'dart:async'; import 'package:firebase_auth/firebase_auth.dart'; -import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -27,9 +26,7 @@ const String kMockLanguage = 'en'; void main() { group('$FirebaseAuth', () { - final String appName = 'testApp'; - final FirebaseApp app = FirebaseApp(name: appName); - final FirebaseAuth auth = FirebaseAuth(app: app); + final FirebaseAuth auth = FirebaseAuth.instance; final List log = []; int mockHandleId = 0; @@ -82,8 +79,7 @@ void main() { expect( log, [ - isMethodCall('currentUser', - arguments: {'app': auth.app.name}), + isMethodCall('currentUser', arguments: null), ], ); }); @@ -96,18 +92,14 @@ void main() { expect( log, [ - isMethodCall('signInAnonymously', - arguments: {'app': auth.app.name}), + isMethodCall('signInAnonymously', arguments: null), isMethodCall( 'getIdToken', - arguments: { - 'refresh': false, - 'app': auth.app.name - }, + arguments: {'refresh': false}, ), isMethodCall( 'getIdToken', - arguments: {'refresh': true, 'app': auth.app.name}, + arguments: {'refresh': true}, ), ], ); @@ -127,7 +119,6 @@ void main() { arguments: { 'email': kMockEmail, 'password': kMockPassword, - 'app': auth.app.name, }, ), ], @@ -144,10 +135,7 @@ void main() { [ isMethodCall( 'fetchProvidersForEmail', - arguments: { - 'email': kMockEmail, - 'app': auth.app.name - }, + arguments: {'email': kMockEmail}, ), ], ); @@ -167,7 +155,6 @@ void main() { arguments: { 'email': kMockEmail, 'password': kMockPassword, - 'app': auth.app.name }, ), ], @@ -188,7 +175,6 @@ void main() { arguments: { 'idToken': kMockIdToken, 'accessToken': kMockAccessToken, - 'app': auth.app.name }, ), ], @@ -202,7 +188,6 @@ void main() { isMethodCall('signInWithPhoneNumber', arguments: { 'verificationId': kMockVerificationId, 'smsCode': kMockSmsCode, - 'app': auth.app.name, }) ]); }); @@ -221,7 +206,6 @@ void main() { 'phoneNumber': kMockPhoneNumber, 'timeout': 5000, 'forceResendingToken': null, - 'app': auth.app.name, }) ]); }); @@ -240,7 +224,6 @@ void main() { arguments: { 'idToken': kMockIdToken, 'accessToken': kMockAccessToken, - 'app': auth.app.name, }, ), ], @@ -259,7 +242,6 @@ void main() { 'linkWithFacebookCredential', arguments: { 'accessToken': kMockAccessToken, - 'app': auth.app.name, }, ), ], @@ -280,7 +262,6 @@ void main() { arguments: { 'authToken': kMockAuthToken, 'authTokenSecret': kMockAuthTokenSecret, - 'app': auth.app.name, }, ), ], @@ -299,7 +280,6 @@ void main() { 'signInWithFacebook', arguments: { 'accessToken': kMockAccessToken, - 'app': auth.app.name, }, ), ], @@ -320,7 +300,6 @@ void main() { arguments: { 'email': kMockEmail, 'password': kMockPassword, - 'app': auth.app.name, }, ), ], @@ -336,11 +315,11 @@ void main() { [ isMethodCall( 'currentUser', - arguments: {'app': auth.app.name}, + arguments: null, ), isMethodCall( 'sendEmailVerification', - arguments: {'app': auth.app.name}, + arguments: null, ), ], ); @@ -355,11 +334,11 @@ void main() { [ isMethodCall( 'currentUser', - arguments: {'app': auth.app.name}, + arguments: null, ), isMethodCall( 'reload', - arguments: {'app': auth.app.name}, + arguments: null, ), ], ); @@ -374,11 +353,11 @@ void main() { [ isMethodCall( 'currentUser', - arguments: {'app': auth.app.name}, + arguments: null, ), isMethodCall( 'delete', - arguments: {'app': auth.app.name}, + arguments: null, ), ], ); @@ -395,7 +374,6 @@ void main() { 'sendPasswordResetEmail', arguments: { 'email': kMockEmail, - 'app': auth.app.name }, ), ], @@ -408,13 +386,12 @@ void main() { expect(log, [ isMethodCall( 'currentUser', - arguments: {'app': auth.app.name}, + arguments: null, ), isMethodCall( 'updateEmail', arguments: { 'email': kMockEmail, - 'app': auth.app.name, }, ), ]); @@ -426,13 +403,12 @@ void main() { expect(log, [ isMethodCall( 'currentUser', - arguments: {'app': auth.app.name}, + arguments: null, ), isMethodCall( 'updatePassword', arguments: { 'password': kMockPassword, - 'app': auth.app.name, }, ), ]); @@ -448,14 +424,13 @@ void main() { expect(log, [ isMethodCall( 'currentUser', - arguments: {'app': auth.app.name}, + arguments: null, ), isMethodCall( 'updateProfile', arguments: { 'photoUrl': kMockPhotoUrl, 'displayName': kMockDisplayName, - 'app': auth.app.name, }, ), ]); @@ -470,7 +445,6 @@ void main() { [ isMethodCall('signInWithCustomToken', arguments: { 'token': kMockCustomToken, - 'app': auth.app.name, }) ], ); @@ -485,7 +459,7 @@ void main() { FirebaseAuth.channel.codec.encodeMethodCall( MethodCall( 'onAuthStateChanged', - {'id': 42, 'user': user, 'app': auth.app.name}, + {'id': 42, 'user': user}, ), ), (_) {}, @@ -515,14 +489,11 @@ void main() { expect( log, [ - isMethodCall('startListeningAuthState', arguments: { - 'app': auth.app.name, - }), + isMethodCall('startListeningAuthState', arguments: null), isMethodCall( 'stopListeningAuthState', arguments: { 'id': 42, - 'app': auth.app.name, }, ), ], @@ -539,7 +510,6 @@ void main() { 'setLanguageCode', arguments: { 'language': kMockLanguage, - 'app': auth.app.name, }, ), ],