Firebase 将多个身份验证提供程序链接到一个帐户
我是本地firebase的新手 我想在登录facebook提供商和google提供商后链接用户 我在互联网上尝试了所有的解决方案,但都奏效了。 这是我的密码Firebase 将多个身份验证提供程序链接到一个帐户,firebase,react-native,react-native-firebase,Firebase,React Native,React Native Firebase,我是本地firebase的新手 我想在登录facebook提供商和google提供商后链接用户 我在互联网上尝试了所有的解决方案,但都奏效了。 这是我的密码 const loginUser = await firebase.auth().signInAndRetrieveDataWithEmailAndPassword('test@gmail.com','password888').then(async function(userRecord) { console.log("Succes
const loginUser = await firebase.auth().signInAndRetrieveDataWithEmailAndPassword('test@gmail.com','password888').then(async function(userRecord) {
console.log("Successfully sign in user:", userRecord.user._user);
let user = firebase.auth().currentUser;
console.log('current user ',user)
let linkAndRetrieveDataWithCredential=firebase.auth().currentUser.linkAndRetrieveDataWithCredential(firebase.auth.FacebookAuthProvider.PROVIDER_ID).then(async u=>{
console.log('linkAndRetrieveDataWithCredential u',u)
}).catch(async (e)=>{
console.log('linkAndRetrieveDataWithCredential error',e)
})
console.log('linkAndRetrieveDataWithCredential error',linkAndRetrieveDataWithCredential)
/**/
await firebase.auth().fetchSignInMethodsForEmail('sss@sss.sss')
.then(async providers => {
console.log('login index providers',providers)
}).catch(function(error){
console.log('login index providers error',error)
})
}).catch(async function(error){
console.log('login error',error,error.email)
if(error.code=='auth/user-not-found'){
}else if(error.code=='auth/wrong-password'){
errorMsg=`${L('password')} ${L('notValid')}`
}
if(errorMsg){
if (Platform.OS === 'android') {
ToastAndroid.show(
errorMsg,
ToastAndroid.LONG
)
} else {
Alert.alert(
'',
errorMsg,
[{ text: L('close'), style: 'cancel' }]
)
}
}
console.log("Error sign in user:", error.code);
})
linkAndRetrieveDataWithCredential
需要一个AuthCredential,在我的应用程序中,我用来获取凭证(您需要按照他们的设置说明进行操作)。
此功能将提示用户登录其facebook帐户并返回AccessToken,然后您从firebase获得凭据,最后是
linkAndRetrieveDataWithCredential
linkToFacebook = () => {
LoginManager.logInWithReadPermissions(['public_profile', 'email'])
.then((result) => {
if (result.isCancelled) {
return Promise.reject(new Error('The user cancelled the request'))
}
// Retrieve the access token
return AccessToken.getCurrentAccessToken()
})
.then((data) => {
// Create a new Firebase credential with the token
const credential = firebase.auth.FacebookAuthProvider.credential(data.accessToken)
// Link using the credential
return firebase.auth().currentUser.linkAndRetrieveDataWithCredential(credential)
})
.catch((error) => {
const { code, message } = error
window.alert(message)
})
}
linkAndRetrieveDataWithCredential
现在已被弃用