Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit e41625c

Browse files
committed
auth example: if sign-up fails, try sign-in with the same credentials
1 parent f9b6f3b commit e41625c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

example/auth/index.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,24 @@ class AuthApp {
6969

7070
_registerUser(String email, String password) async {
7171
if (email.isNotEmpty && password.isNotEmpty) {
72+
var trySignin = false;
7273
try {
7374
await auth.createUserWithEmailAndPassword(email, password);
75+
} on fb.FirebaseError catch (e) {
76+
if (e.code == "auth/email-already-in-use") {
77+
trySignin = true;
78+
}
7479
} catch (e) {
7580
error.text = e.toString();
7681
}
82+
83+
if (trySignin) {
84+
try {
85+
await auth.signInWithEmailAndPassword(email, password);
86+
} catch (e) {
87+
error.text = e.toString();
88+
}
89+
}
7790
} else {
7891
error.text = "Please fill correct e-mail and password.";
7992
}

0 commit comments

Comments
 (0)