简体   繁体   English

使用不同的提供者反应原生 firebase 身份验证

[英]React native firebase authentication using different providers

Firstly I create new user in firebase using function createUserWithEmailAndPassword(jamesdmurphy51@gmail.com, password) .首先,我使用 function createUserWithEmailAndPassword(jamesdmurphy51@gmail.com, password)在 firebase 中创建新用户。

I then sign in using Facebook using the code below然后我使用下面的代码使用 Facebook 登录

const result = await LoginManager.logInWithPermissions(['public_profile', 'email']);
const data = await AccessToken.getCurrentAccessToken();
const firebaseCredential = await auth.FacebookAuthProvider.credential(data.accessToken);
const fbUserObj = await auth().signInWithCredential(firebaseCredential);

Problem is that it creates a completely seperate user account with seperate UID....even though the email address linked to the facebook account is the same one that was used to createUserWithEmailAndPassword .问题是它使用单独的 UID 创建了一个完全独立的用户帐户......即使链接到 facebook 帐户的 email 地址与用于createUserWithEmailAndPassword的地址相同。 How do I make it so user can log into exising account using Facebook?如何使用户可以使用 Facebook 登录现有帐户?

When you call auth().signInWithCredential(firebaseCredential) , you're indeed creating a new account in Firebase Authentication.当您调用auth().signInWithCredential(firebaseCredential)时,您确实在 Firebase 身份验证中创建了一个新帐户。

If you instead want to link the Facebook credentials to an existing account, you need to call linkWithPopup or linkWithRedirect as shown in the Firebase documentation on linking accounts .如果您想将 Facebook 凭证链接到现有帐户,则需要调用linkWithPopuplinkWithRedirect ,如 Firebase 文档中的链接帐户所示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM