// Check if user is logged in
onAuthStateChanged(async (user: any, _next: any) => {
if (user) {
console.log(user);
} else {
const result = await signInWithPopup(auth, provider);
console.log(result);
}
});此代码给出了错误An argument for 'nextOrObserver' was not provided. Expected 2-4 arguments, but got 1.。但据我所知,这个函数有两个参数。
这将导致类型赋值编译器拒绝编译。
发布于 2022-08-15 13:58:33
,但据我所知,这个函数有两个参数。
它指出,onAuthStateChange需要2个参数,而不是您编写的函数需要2个参数。事实上,您的函数应该只有一个参数。您缺少的部分是需要将auth实例传递到onAuthStateChanged中。从调用signInWithPopup的方式来看,我假设变量auth包含这一点。如果没有,您可以调用getAuth来获得它:
import { getAuth, onAuthStateChanged, User } from "firebase/auth"
// ...
onAuthStateChanged(
auth, // or getAuth()
async (user: User | null) => {
// ...
}
);https://stackoverflow.com/questions/73361927
复制相似问题