首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >onAuthStateChanged不识别多个参数

onAuthStateChanged不识别多个参数
EN

Stack Overflow用户
提问于 2022-08-15 13:50:36
回答 1查看 28关注 0票数 1
代码语言:javascript
复制
// 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.。但据我所知,这个函数有两个参数。

这将导致类型赋值编译器拒绝编译。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-15 13:58:33

,但据我所知,这个函数有两个参数。

它指出,onAuthStateChange需要2个参数,而不是您编写的函数需要2个参数。事实上,您的函数应该只有一个参数。您缺少的部分是需要将auth实例传递到onAuthStateChanged中。从调用signInWithPopup的方式来看,我假设变量auth包含这一点。如果没有,您可以调用getAuth来获得它:

代码语言:javascript
复制
import { getAuth, onAuthStateChanged, User } from "firebase/auth"
// ...
onAuthStateChanged(
  auth, // or getAuth()
  async (user: User | null) => {
   // ...
  }
);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73361927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档