I'm getting an error "Error type 'AuthResult' is not a subtype of type 'FirebaseUser' in type cast" when I'm trying to login or signup

I'm making a flutter app for my college project, where I'm adding a login and signup page and authenticating it via Firebase, and when I click login the debug console says "Error type 'AuthResult' is not a subtype of type 'FirebaseUser' in type cast" and when I reload the app after this error it successfully logs in.

Everything was working best before the update of the firebase_auth package to 0.12.0 after this update, the methods "signInWithEmailAndPassword()" and "createUserWithEmailAndPassword()" throwing an error "A value of type 'AuthResult' can't be assigned to a variable of type 'FirebaseUser'. Try changing the type of the variable, or casting the right-hand type to 'FirebaseUser'", so I added a cast as FirebaseUser which fixed the error and the app was built successfully but when i clicked on login or create account, debug console said Error type 'AuthResult' is not a subtype of type 'FirebaseUser' in type cast

the main login and create account function code before the update of firebase_auth 0.12.0

Future<String> signIn(String email, String password) async {
FirebaseUser user = await 
FirebaseAuth.instance.signInWithEmailAndPassword(
    email: email, password: password);
return user.uid;
}

Future<String> createUser(String email, String password) async {
FirebaseUser user = await 
FirebaseAuth.instance.createUserWithEmailAndPassword(
    email: email, password: password);
return user.uid;
}

the above code was working fine, after the update (firebase_auth 0.12.0) the same code started throwing this error,

A value of type 'AuthResult' can't be assigned to a variable of type 
'FirebaseUser'.
Try changing the type of the variable, or casting the right-hand type to 
'FirebaseUser'.dart(invalid_assignment)

I fixed the error by casting "FirebaseUser" as shown below

Future<String> signIn(String email, String password) async {
FirebaseUser user = await 
FirebaseAuth.instance.signInWithEmailAndPassword(
    email: email, password: password) as FirebaseUser;
return user.uid;
}

Future<String> createUser(String email, String password) async {
FirebaseUser user = await 
FirebaseAuth.instance.createUserWithEmailAndPassword(
    email: email, password: password) as FirebaseUser;
return user.uid;
}

this new code didn't threw an error in compilation but when I try to login or create new account it throws an error in debug console Error type 'AuthResult' is not a subtype of type 'FirebaseUser' in type cast and the new created account is successfully created on firebase but the app doesn't go on the next page but as soon as i reload it starts with the page that should come after login and creation of account(sign out is working perfectly)

This is a breaking change in the plugin and its documented here https://pub.dev/packages/firebase_auth#0120

So you shouldn't do any type of casting you just have to refactor your code to adopt the new changes :

FirebaseUser user = (await FirebaseAuth.instance.
signInWithEmailAndPassword(email: email, password: password))
.user;

Lauv - I Like Me Better [Official Video], Lauv's debut album, ~how i'm feeling~ is available now: http://lauv.lnk.to/ howimfeelingYD I Duration: 3:26 Posted: Aug 10, 2017 Create an account or log in to Instagram - A simple, fun & creative way to capture, edit & share photos, videos & messages with friends & family.

I face the same issue. Just modify to be:

final FirebaseUser user = (await _auth.signInWithCredential(credential)).user;

See https://github.com/flutter/flutter/issues/38757#issuecomment-522307525

I (Kendrick Lamar song), noun, plural I's or Is, i's or is. the ninth letter of the English alphabet, a vowel. any spoken sound represented by the letter I or i, as in big, nice, or ski. something� I 1 (ī) pron. Used to refer to oneself as speaker or writer. n. pl. I's The self; the ego. [Middle English, from Old English ic; see eg in Indo-European roots.] Usage Note

I had same error and changed code to:

FirebaseUser user = (await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password)).user;

The app works as expected on a real device, without an error in the console, but Visual Studio Code shows red underline at the end below user and outputs an error:

The getter 'user' isn't defined for the class 'FirebaseUser'. Try importing the library that defines 'user', correcting the name to the name of an existing getter, or defining a getter or field named 'user'.

[Solution] Restart VS Code. VS Code uses the old library until restart.

I, Create an account or log in to Instagram - A simple, fun & creative way to capture, edit & share photos, videos & messages with friends & family. The sixteenth letter of the Hungarian alphabet, called í and written in the Latin script.

It has been changed what you should do is AuthResult result = await _firebaseAuth.signInWithEmailAndPassword( email: email, password: password); FirebaseUser user = result.user;

Instagram, The ninth letter of the basic modern Latin alphabet. I (lower case ı). The letter i without a dot above, in both the upper case and the lower case versions. î (lower case, upper case Î) The twelfth letter of the Romanian alphabet, called î or î din i and written in the Latin script.

signInWithEmailAndPassword returns AuthResult and AuthResult class contains instance variable user of type FirebaseUser. So You have to change your code as following way.

FirebaseUser userDetails = (await FirebaseAuth.instance
          .signInWithEmailAndPassword(Credentialsxxx)).user;
print('sign in : ${userDetails.uid}');

I, I definition is - the 9th letter of the English alphabet. How to use i in a sentence. me or I? I have a PHP source file where  characters automatically got added in! I don't know from where they have come. I'm not getting any parse errors but it results in weird behavior in the execution

I, Windows is either a registered trademark or a trademark of Microsoft Corporation in the United States and/or other countries. Mac is a trademark of Apple Inc. Bir hesap oluştur veya Instagram'a giriş yap - Fotoğraf ve videolar çekip düzenlemenin, bu fotoğrafları, videoları ve mesajları arkadaşlarınla ve akrabalarınla paylaşmanın basit, eğlenceli ve yaratıcı yolu.

[PDF] USCIS Form I-9, Consideration of Deferred Action for Childhood Arrivals. Department of Homeland Security. U.S. Citizenship and Immigration Services. USCIS. Form I- 821D. Log in to i-Ready®, online assessment and instruction that helps teachers provide all students a path to proficiency and growth in reading and mathematics.

[PDF] Form I-821D, Google allows users to search the Web for images, news, products, video, and other content.

Comments
  • Thank You so much for your help that worked for me, now there is no error but still it's not switching to the Homepage(the page which supposed to come after login), the debug console says "Signed in" no error but doesn't go ahead either. I hope you can help
  • I think this might be another issue but not related to firebase_auth and in your question, you don't mention how you are doing the transition to the homepage . i guess you better make that in another question
  • Ok, Thanks again
  • You just saved me hours of trouble. God bless you!
  • After restartarting VS code the error persisted, however restarting my computer did the trick. Thank you sir