TypeError:无法读取带有firebase reauthenticateWithCredential的未定义属性“ credential”

Tay*_*tin 5 javascript firebase firebase-authentication

不完全确定我在这里做错了什么,我看过其他论坛上的帖子,这是他们说的要重新验证用户身份。但我收到以下错误:

TypeError: Cannot read property 'credential' of undefined 在此行上:

const credentials = fire.auth.EmailAuthProvider.credential(currentUser.email, user.currentPass);

这是代码:

 const currentUser = fire.auth().currentUser;
 const credentials = fire.auth.EmailAuthProvider.credential(currentUser.email, user.currentPass);
 currentUser
  .reauthenticateWithCredential(credentials)
  .then(() => {
    alert('Success');
  })
  .catch(err => {
    alert(err);
  });
Run Code Online (Sandbox Code Playgroud)

dav*_*ouk 2

您以错误的方式导入了 firebase。是文档中的内容。 官方文件

const firebase = require('firebase');
const cred = firebase.auth.EmailAuthProvider.credential(
    email,
    password
);
Run Code Online (Sandbox Code Playgroud)