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

移动端Firebase Google登录CORS跨域问题求助

Google账号登录(signInWithPopup)在Android端触发CORS跨域错误问题

我的网站注册页面基于Angular框架开发,使用@angular/fire提供的Firebase Auth服务,通过signInWithPopup实现Google账号注册登录。该功能在PC端Chrome、Firefox浏览器中正常运行,但在Android设备上执行时触发CORS跨域错误:请求Google身份工具接口时因缺少Access-Control-Allow-Origin头被拦截。

已尝试以下方案但未解决问题:

  • 更换华为、三星设备测试,问题一致;
  • 确认Firebase控制台已正确配置授权域名;
  • 开启第三方Cookie与弹窗权限。

相关环境信息:

  • 网站域名:http://77.37.125.123/(未配置SSL);
  • 部署环境:Hostinger VPS + Nginx;

核心代码如下:

AuthService类

@Injectable({
  providedIn: 'root'
})
export class AuthService {

  constructor(
    private afAuth: AngularFireAuth,
    private http: HttpClient
  ) {}

  private readonly api_url: string = environment.apiUrl

  async googleAuth() {
    return await this.afAuth.signInWithPopup(new GoogleAuthProvider())
  }

  // 其他代码...
}

signup.component.ts调用代码

googleUserSubmitted() {

    this.loadingGoogleUser = true

    this.signupWithGoogle()
      .then((res) => {

        res.user?.getIdToken()
          .then((token) => {

            this.googleForm.patchValue({
              email: res.user?.email,
              name: res.user?.displayName,
              tokenID: token
            })

          })
          .finally(() => {
            this.loadingGoogleUser = false
          })

      })
      .catch(() => {
        this.loadingGoogleUser = false
      })
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 05:57:06