Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,14 @@ class FlutterFirebaseAuthPlugin :
password: String,
callback: (Result<InternalUserCredential>) -> Unit
) {
getAuthFromPigeon(app).createUserWithEmailAndPassword(email, password).addOnCompleteListener {
task ->
completeAuthResult(task, callback)
}
val task =
try {
getAuthFromPigeon(app).createUserWithEmailAndPassword(email, password)
} catch (e: Exception) {
callback(Result.failure(FlutterFirebaseAuthPluginException.parserExceptionToFlutter(e)))
return
}
task.addOnCompleteListener { completed -> completeAuthResult(completed, callback) }
}

override fun signInAnonymously(
Expand Down Expand Up @@ -230,10 +234,14 @@ class FlutterFirebaseAuthPlugin :
password: String,
callback: (Result<InternalUserCredential>) -> Unit
) {
getAuthFromPigeon(app).signInWithEmailAndPassword(email, password).addOnCompleteListener { task
->
completeAuthResult(task, callback)
}
val task =
try {
getAuthFromPigeon(app).signInWithEmailAndPassword(email, password)
} catch (e: Exception) {
callback(Result.failure(FlutterFirebaseAuthPluginException.parserExceptionToFlutter(e)))
return
}
task.addOnCompleteListener { completed -> completeAuthResult(completed, callback) }
}

override fun signInWithEmailLink(
Expand Down Expand Up @@ -308,11 +316,16 @@ class FlutterFirebaseAuthPlugin :
) {
val firebaseAuth = getAuthFromPigeon(app)
val task =
if (actionCodeSettings == null) {
firebaseAuth.sendPasswordResetEmail(email)
} else {
firebaseAuth.sendPasswordResetEmail(
email, PigeonParser.getActionCodeSettings(actionCodeSettings))
try {
if (actionCodeSettings == null) {
firebaseAuth.sendPasswordResetEmail(email)
} else {
firebaseAuth.sendPasswordResetEmail(
email, PigeonParser.getActionCodeSettings(actionCodeSettings))
}
} catch (e: Exception) {
callback(Result.failure(FlutterFirebaseAuthPluginException.parserExceptionToFlutter(e)))
return
}
task.addOnCompleteListener { completed -> completeVoid(completed, callback) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,41 @@ void main() {
fail(e.toString());
}
});

test(
'fails with a FirebaseAuthException if the email or password is empty',
() async {
await expectLater(
FirebaseAuth.instance.createUserWithEmailAndPassword(
email: '',
password: testPassword,
),
throwsA(
isA<FirebaseAuthException>().having(
(e) => e.code,
'code',
'unknown',
),
),
);
await expectLater(
FirebaseAuth.instance.createUserWithEmailAndPassword(
email: generateRandomEmail(),
password: '',
),
throwsA(
isA<FirebaseAuthException>().having(
(e) => e.code,
'code',
'unknown',
),
),
);
},
// Only the Android SDK rejects empty values itself; elsewhere the
// error comes from the backend and differs per method.
skip: kIsWeb || defaultTargetPlatform != TargetPlatform.android,
);
});

group('isSignInWithEmailLink()', () {
Expand Down Expand Up @@ -592,6 +627,23 @@ void main() {
fail(e.toString());
}
});

test(
'fails with a FirebaseAuthException if the email is empty',
() async {
await expectLater(
FirebaseAuth.instance.sendPasswordResetEmail(email: ''),
throwsA(
isA<FirebaseAuthException>().having(
(e) => e.code,
'code',
'unknown',
),
),
);
},
skip: kIsWeb || defaultTargetPlatform != TargetPlatform.android,
);
}, skip: !kIsWeb && Platform.isWindows);

group('sendSignInLinkToEmail()', () {
Expand Down Expand Up @@ -908,6 +960,40 @@ void main() {
fail(e.toString());
}
});

test(
'throws a FirebaseAuthException if the email or password is empty',
() async {
await expectLater(
FirebaseAuth.instance.signInWithEmailAndPassword(
email: '',
password: testPassword,
),
throwsA(
isA<FirebaseAuthException>().having(
(e) => e.code,
'code',
'unknown',
),
),
);
await expectLater(
FirebaseAuth.instance.signInWithEmailAndPassword(
email: testEmail,
password: '',
),
throwsA(
isA<FirebaseAuthException>().having(
(e) => e.code,
'code',
'unknown',
),
),
);
},
skip: kIsWeb || defaultTargetPlatform != TargetPlatform.android,
);

test(
'should not throw error when app is deleted and reinit with same app name',
() async {
Expand Down
Loading