无法链接其他auth方法 - firebase auth

时间:2017-10-26 10:41:06

标签: 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();

我认为fire.auth或fire.auth()

有问题

由于

1 个答案:

答案 0 :(得分:1)

从Firebase JS 4.0.0开始,

link已被删除,转而使用linkWithCredentialhttps://firebase.google.com/support/release-notes/js#4.0.0

还要确保当前用户已做好准备:

firebase.auth().onAuthStateChange(user => {
  if (user) {
    // currentUser is not null.
  } else {
    // currentUser is null.
  }
});