Firebase fetchSignInMethodsForEmail 返回未定义

Luc*_*uto 1 firebase reactjs firebase-authentication

我正在尝试从 firebase 获取数据,以便了解我的用户是否已经拥有帐户。找到了这个fetchSignInMethodsForEmail

问题是这个:

在此输入图像描述

“i”属性返回未定义,但之后显示值“password”。当我尝试获取时,我只会得到未定义的结果。

这是我正在使用的方法:

readUser = (user) => {
        user = firebase.auth().fetchSignInMethodsForEmail(this.state.email);
    
        
        console.log(user);
        console.log(user.i);
        
       
    }
Run Code Online (Sandbox Code Playgroud)

它返回 undefined for console.log(user.i);,但我需要它返回值“password”或数组长度。

Jan*_*roň 5

fetchSignInMethodsForEmail返回承诺,因此您需要调用它,例如在异步函数中等待:

readUser = async (user) => {
    user = await firebase.auth().fetchSignInMethodsForEmail(this.state.email);

    console.log(user);
    console.log(user.i);
}
Run Code Online (Sandbox Code Playgroud)