我正在使用 Firebase oAuth 构建应用程序。我遵循了所有说明,但我的代码返回了一个错误,指出“asyn arrow function expected no return value”。
我看到有多个标题相同的帖子,但没有找到答案。
import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';
export const auth = firebase.auth();
export const firestore = firebase.firestore();
const config = {
apiKey: 'XXXXXXXXX',
authDomain: 'XXXXXXXXX',
projectId: 'XXXXXXXXX',
storageBucket: 'XXXXXXXXX',
messagingSenderId: 'XXXXXXXXX',
appId: 'XXXXXXXXX',
};
firebase.initializeApp(config);
export const createUserProfileDocument = async (userAuth, additionalData) => {
if (!userAuth) return;
const userRef = firestore.doc(`users/${userAuth.uid}`);
const snapShot = await userRef.get();
if (!snapShot.exists) {
const { displayName, email } = userAuth;
const createdAt = new Date();
try {
await userRef.set({
displayName,
email,
createdAt,
...additionalData,
});
} catch (error) {
console.log('error creating user', error.message);
}
}
return userRef;
};
const provider = new firebase.auth.GoogleAuthProvider();
provider.setCustomParameters({ prompt: 'select_account' });
export const signInWithGoogle = () => auth.signInWithPopup(provider);
export default firebase;
原文由 Augusto Mallmann 发布,翻译遵循 CC BY-SA 4.0 许可协议
将第一行从
if (!userAuth) return
更改为if (!userAuth) return {}
,这应该可以解决问题解释
你遇到的错误最后说
consistent-return
,这基本上意味着你的函数应该始终返回相同的类型。考虑到这一点,如果我们看一下函数的第一行
此行返回
void
,但函数的最后一行返回其他类型userRef
绝对不是类型void
这就是您出现此错误的原因。