You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase中匿名账号升级及linkWithPopup报错时error.credential始终为undefined的问题求助

Firebase中匿名账号升级及linkWithPopup报错时error.credential始终为undefined的问题求助

各位大佬好,我最近在做Firebase匿名账号升级的功能,打算通过linkWithPopup把当前的匿名用户和Google账号关联起来。按照官方的逻辑,当遇到auth/credential-already-in-use这类错误时,应该能通过error.credential拿到凭证,再调用signInWithCredential完成账号的恢复登录,但实际跑起来后,error.credential一直是undefined,完全没法走后续的流程。

下面是我的代码:

linkWithPopup(auth.currentUser, googleAuthProvider)
  .then((result) => {
    const user = result.user;
    console.log("Anonymous account successfully upgraded", user);
    window.location = redirectUrl;
  }).catch((error) => {
    console.log("Error upgrading anonymous account", error);
    console.log(error.credential); // 这里始终打印undefined
    if (error.credential) {
      signInWithCredential(auth, error.credential)
        .then((result) => {
          const user = result.user;
          console.log("recovered");
        })
        .catch((error) => {
          console.log("error in google auth recovery", error);
        });
    }
  });

我已经确认触发的错误确实是auth/credential-already-in-use,但就是拿不到error.credential,有没有朋友遇到过类似的问题?或者我哪里的代码逻辑有问题,麻烦帮忙看看,谢谢了!

备注:内容来源于stack exchange,提问作者pmac

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 12:39:35