作者:手机用户2502914387 | 来源:互联网 | 2023-06-06 09:27
我有一个流畅的应用程序,希望用户同时通过FB和Google进行身份验证。我不希望有多个帐户,而只需要一个链接两个帐户的帐户。
我正在使用:
firebase_auth 0.15.1
google_sign_in 4.0.14
facebook_plugin 3.0.0
当该用户的帐户已经存在于其他提供商处时,我无法获得该用户的电子邮件地址。为了使用API调用“ fetchSignInmethodsForEmail”获得该用户的提供者列表,需要使用该电子邮件。
这里是一个示例:
1:使用Google凭据登录的用户。该帐户是在Firebase中创建的,并且已关联Google
2:用户现在注销
3:用户现在尝试使用相同的电子邮件登录FB。
-用户遇到以下错误
code:"ERROR_accOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL"
details: null
message: "An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address.,**null**))
如您所见,电子邮件为空。我需要电子邮件以获取提供商列表。然后,我可以将用户重定向到正确的提供程序
这是我的代码段
Future signInWithFacebook({bool isIos}) async {
AuthCredential credential;
try {
final FacebookLoginResult result = await facebookLogin.logIn(['email']);
if (result.accessToken != null) {
credential = FacebookAuthProvider.getcredential(
accessToken: result.accessToken.token
);
AuthResult authResult = await _firebaseAuth.signInWithCredential(
credential,);
firebaseUser = authResult.user;
return firebaseUser;
} catch (e) {
throw Exception(e);
}
return null;
}
感谢您的帮助