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

Firebase V9中使用signInWithCredential结合OAuthProvider实现Apple登录报错求助

Apple登录Firebase V9报错:TypeError: undefined is not an object (evaluating 'credential._getIdTokenResponse')

核心错误原因

Firebase V9模块化版本的signInWithCredential函数需要两个必填参数:Firebase Auth实例和生成的OAuth凭证,你的代码中仅传入了凭证,缺少Auth实例,导致内部调用失败。

修正步骤

  1. 确保初始化Firebase Auth实例
    先导入并获取Auth实例:

    import { getAuth } from "firebase/auth";
    const auth = getAuth();
    
  2. 修正signInWithCredential调用
    调用时同时传入Auth实例和凭证:

    signInWithCredential(auth, authCredential)
      .then((userCredential) => {
        // 这里返回的是userCredential,不是credential
        console.log(userCredential.user.providerId);
      })
      .catch(e => { console.log("error in apple auth: ", e) })
    

额外检查项

  • 确认OAuthProvider的导入正确,V9模块化需从firebase/auth导入:
    import { OAuthProvider } from "firebase/auth";
    
  • 验证nonce哈希逻辑:Apple要求传入的nonce参数是原始nonce的SHA256哈希值,确保hashedNonce的生成逻辑正确,且与rawNonce一一对应。

内容的提问来源于stack exchange,提问作者goodkidMadCoder

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.26 07:18:19