Flutterfire: [fireabse_auth] call reauthenticateWithCredential by EmailAuthProvider using current email and password (NoSuchMethodError: The method '[]' was called on null).

Created on 13 Oct 2019  路  11Comments  路  Source: FirebaseExtended/flutterfire

description

  • I use firebase_auth: 0.14.0.
  • I would like to update the user's email, but if the user's last sign-in time does not meet the security threshold, I need to use the reauthentication method to resolve.
  • I tried to call reauthenticateWithCredential on EmailAuthProvider with my current email address and password before firebaseUser.updateEmail, but the data returned from reauthenticateWithCredential on iOS has no user and crashes with the following error.

error

Tried calling: []("user")
flutter: 馃挜 #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
#1      new AuthResult._ (package:firebase_auth/src/auth_result.dart:12:36)
#2      FirebaseUser.reauthenticateWithCredential (package:firebase_auth/src/firebase_user.dart:214:23)
...
````

## my code

```dart 
final baseUser = await _firebaseAuth.currentUser();
// occurs error
final authResult = await baseUser.reauthenticateWithCredential(
  EmailAuthProvider.getCredential(
    email: baseUser.email,
    password: password,
  ),
);
return authResult.user;

workaround

  • I downgraded to 0.11.1+12, and it works.
final baseUser = await _firebaseAuth.currentUser();
final firebaseUser = await baseUser.reauthenticateWithCredential(
  EmailAuthProvider.getCredential(
    email: baseUser.email,
    password: password,
  ),
);
return firebaseUser;
regression bug

Most helpful comment

@masashi-sutou

The issue at https://github.com/flutter/flutter/issues/37542 has been closed and moved here. Future collaboration on this issue will be done here.

All 11 comments

@masashi-sutou

The issue at https://github.com/flutter/flutter/issues/37542 has been closed and moved here. Future collaboration on this issue will be done here.

I am also having this issue, but in my case I called reauthenticateWithCredential for updating the user's password. So thig bug impacts several use cases.

I am on Android and my error is:

D/FirebaseAuth(16156): Notifying id token listeners about user ( xxxxxxxxxxxxxxxxxxxxxxxxxxxx ).
I/flutter (16156): NoSuchMethodError: The method '[]' was called on null.
I/flutter (16156): Receiver: null
I/flutter (16156): Tried calling: []("user")

I think this is the same issue as #76 and will be fixed in #237

@collinjackson I am still getting the NoSuchMethodError: The method '[]' was called on null., even after updating to version 0.15.0 and running pub get.

Make sure you run pub upgrade when changing version numbers...

AFAIK pub upgrade will only be necessary if I don't change the minimum version. Since I changed the minimum version, pub is obligated to respect it and never use a version less than 0.15.0

I thought that originally as well, but pub get doesn't seem to update it even if you change the version. You can verify this by inspecting the pubspec.lock file.

https://github.com/flutter/flutter/issues/44171#issuecomment-553696378

Isn't that only for plugins?

anyway, my pubspec.lock was updated by pub get, I will try a flutter clean.

flutter clean did the trick.

Thanks @feinstein. I included an integration test for the change so it should be working... please let us know if you figure it out.

Was this page helpful?
0 / 5 - 0 ratings