链接两个firebase auth方法给我错误 - javascript

时间:2017-10-26 12:09:38

标签: javascript firebase firebase-authentication

我正在尝试将电子邮件,密码验证方法与当前的 PhoneAuth 方法相关联。

但它给了我一个错误:

  

无法读取未定义的属性“链接”

这是代码:

import { firebaseAuth,fire,  messaging } from '../../config/constants';

var credential = fire.auth.EmailAuthProvider.credential(email, password);
fire.auth.currentUser.link(credential).then(function(user) {
  console.log("Account linking success", user);
}, function(error) {
  console.log("Account linking error", error);
});

config / constants

import firebase from 'firebase'
require("firebase/firestore");
const config = {
  apiKey: "AIzxxxxxxxxxxxxxxxxxxKXI",
    authDomain: "payxxxxxxxxxxxxja1.firebaseapp.com",
    databaseURL: "https://payxxxxxxxxxxja1.firebaseio.com",
    projectId: "payxxxxxxxxxxxxja1",
    storageBucket: "payxxxxxxxxxxxja1.appspot.com",
    messagingSenderId: "281xxxxx5xxxxx6"
}

firebase.initializeApp(config)

export const fire = firebase
export const ref = firebase.database().ref()
export const firebaseAuth = firebase.auth
export const messaging = firebase.messaging();

请帮我解决这个问题。谢谢

1 个答案:

答案 0 :(得分:0)

以下是他们在Docs中提到的内容。

  

将AuthCredential对象传递给已登录的用户   linkWithCredential方法:

auth.currentUser.link(credential).then(function(user) {
  console.log("Account linking success", user);
}, function(error) {
  console.log("Account linking error", error);
});

以下是解决问题的方法。

auth.currentUser.linkWithCredential(credential).then(function(user) {
  console.log("Account linking success", user);
}, function(error) {
  console.log("Account linking error", error);
});

只需将link替换为linkWithCredential即可。这就是Doc作家的愚蠢。