Reputation: 9
There is a tutorial series on Flutter & Firebase authentication. When I've cloned the project and run, the following error was dropped in auth.dart and in login_page.dart. How could I fix this please?
A value of type 'AuthResult' can't be assigned to a variable of type 'FirebaseUser'
Code is given below:
class Auth implements BaseAuth {
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
Future<String> signIn(String email, String password) async {
FirebaseUser user = await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password);
return user.uid;
}
Future<String> createUser(String email, String password) async {
FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
return user.uid;
}
and error in login method 'signInWithEmailAndPassword' isn't defined for the class 'BaseAuth'. Code is given below:
Future<void> validateAndSubmit() async {
if (validateAndSave()) {
try {
final BaseAuth auth = AuthProvider.of(context).auth;
if (_formType == FormType.login) {
final String userId = await auth.signInWithEmailAndPassword(_email, _password);
print('Signed in: $userId');
} else {
final String userId = await auth.createUserWithEmailAndPassword(_email, _password);
print('Registered user: $userId');
}
widget.onSignedIn();
} catch (e) {
print('Error: $e');
}
}
}
Upvotes: 1
Views: 365
Reputation: 7308
Recently there have been updates on the package firebase_auth now the methods return a Future<AuthResult>
. If you want your FirebaseUser
you need to get the AuthResult.user
.
Something like this should work for you :
FirebaseUser user = (await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password)).user;
Upvotes: 1