fetchProvidersForEmail返回undefined

时间:2018-01-04 18:42:26

标签: firebase firebase-authentication

我正在尝试使用fetchProvidersForEmail检查是否存在电子邮件,但是我编写的函数仍然未定义返回。

var emailExists = (emailAddress) => {
firebase.auth().fetchProvidersForEmail(emailAddress)
    .then((providers) => {
    return providers.length > 0;
    });
};

除此之外,我也试过

var emailExists = (emailAddress) => {
    var exists = false;

    firebase.auth().fetchProvidersForEmail(emailAddress)
        .then((providers) => {
        exists = providers.length > 0;
        });

    return exists;
};

return ...替换为console.log(providers.length > 0)时,会返回我期望的值。我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

你必须这样做:

 var emailExists = (emailAddress) => {   
 return firebase.auth().fetchProvidersForEmail(emailAddress)
     .then((providers) => {
     return providers.length > 0;
     }); };

firebase.auth()。fetchProvidersForEmail返回一个promise,其布尔值是providers.length> 0或不。

但是在您的emailExists功能中,您没有返回承诺。所以返回undefined。