我正在尝试使用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)
时,会返回我期望的值。我在这里做错了什么?
答案 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。