Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

FirebaseUser no longer exists in firebase_auth

ErrorUndefined class 'FirebaseUser'.

Short answer

FirebaseUser was renamed User in firebase_auth 0.18. AuthResult became UserCredential, currentUser() became a plain getter, and onAuthStateChanged became authStateChanges(). Replace each name, import package:firebase_auth/firebase_auth.dart, and read the signed-in user from credential.user.

  • Applies to firebase_auth current, Flutter 3.3x stable, Dart 3.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List every old name left in the project, so you can replace all of them in one pass.

    grep -rn "FirebaseUser\|AuthResult\|onAuthStateChanged\|currentUser()" lib/
  2. 2Match what you see, then jump to its fix

    1. 1Undefined class 'FirebaseUser' on a field, parameter or return typeThe class was renamed from FirebaseUser to UserFix
    2. 2Undefined class 'AuthResult', or 'user' used on a result of the wrong typeSign-in methods return UserCredential, not AuthResultFix
    3. 3Code still calls currentUser() as a method, or still uses onAuthStateChangedcurrentUser() and onAuthStateChanged were replacedFix

What does the error look like?

  • Undefined class 'FirebaseUser'.
  • Undefined class 'AuthResult'.

Cause 1 of 3

The class was renamed from FirebaseUser to User

1Check

The firebase_auth changelog for 0.18.0 lists the rename as a breaking change. Code written for older releases still uses the old name.

grep -rn "FirebaseUser" lib/

2Fix

Rename the type to User and make sure the package is imported. Hide the name if it clashes with your own User class.

import 'package:firebase_auth/firebase_auth.dart';

User? _user = FirebaseAuth.instance.currentUser;

3Verify

dart analyze no longer reports the undefined class.

dart analyze

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 3

Sign-in methods return UserCredential, not AuthResult

1Check

Since 0.18.0, AuthResult is called UserCredential, and the signed-in user is its user property.

grep -rn "AuthResult" lib/

2Fix

Change the type, and read the user from the credential.

final UserCredential credential = await FirebaseAuth.instance
    .signInWithEmailAndPassword(email: email, password: password);
final User? user = credential.user;

3Verify

The file analyzes without errors.

dart analyze lib/

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

currentUser() and onAuthStateChanged were replaced

1Check

The same release made currentUser a synchronous getter, and deprecated onAuthStateChanged in favour of authStateChanges().

grep -rn "onAuthStateChanged\|currentUser()" lib/

2Fix

Use the getter without parentheses and listen to the new stream.

final User? current = FirebaseAuth.instance.currentUser;

FirebaseAuth.instance.authStateChanges().listen((User? user) {
  // null means signed out
});

3Verify

Run the app, sign in and out, and watch the stream fire.

flutter run

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Read the package changelog before a major firebase_auth upgrade.
  • Run dart analyze in CI so a rename shows up as a failed check, not a runtime surprise.
  • Keep old tutorials for reference only and check their API names against the current docs.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.