【问题标题】:Firebase Authentication: auth/auth-domain-config-requiredFirebase 身份验证:auth/auth-domain-config-required
【发布时间】:2017-11-17 15:14:36
【问题描述】:

我在使用 firebase.auth().signInWithPopup(provider) 时遇到 auth-domain-config-required 错误。

我已经尝试过使用 Google 和 Facebook。我已经在我的托管网站上进行了测试,它运行良好。你可以现场测试:Quiver Chat Demo

我怀疑 localhost:3333 有问题...它不喜欢我的端口吗?我无法将端口添加到 授权域 列表,将其添加到我的 authDomain: 配置也无济于事。

这是我的身份验证代码,但正如您从下面的屏幕截图中看到的那样,我尝试了一堆不同的 authDomain 值。

  <script src="https://quiver-four.firebaseapp.com/__/firebase/4.6.2/firebase-app.js"></script>
  <script src="https://quiver-four.firebaseapp.com/__/firebase/4.6.2/firebase-auth.js"></script>
  <script>
    // Initialize Firebase
    var config = {
      apiKey: "AIzaSyCzNxnQ6WCJKejq6SBd7NqhVskxEOmDq_Y",
      authDomain: "quiver-four.firebaseapp.com",
      databaseURL: "https://quiver-four.firebaseio.com",
      projectId: "quiver-four",
      storageBucket: "quiver-four.appspot.com",
      messagingSenderId: "1082528354495"
    };
    firebase.initializeApp(config);
  </script>

尝试 localhost:3333


尝试本地主机


正在尝试 quiver-four.firebaseapp.com


域已添加

【问题讨论】:

  • 嗨,克里斯。您可以编辑您的问题以包含您如何初始化 Firebase 应用程序的代码吗?我的第一个猜测是那里出了点问题。
  • 嘿弗兰克,我试了三个品种,都复制了。

标签: javascript firebase firebase-authentication


【解决方案1】:

您不得在 Firebase 应用初始化配置中提供正确的 authDomain。 您可以从 Firebase 控制台获取该网络 sn-p。 authDomain 的格式为 projectName.firebaseapp.com

【讨论】:

  • 对不起。我试过了,我试图链接到屏幕截图......但他们没有出现在我的第一篇文章中。我已经编辑了问题以使其明确。
  • 我检查了您的网站。我没有收到您描述的错误,但我注意到使用重定向登录时出现错误,因为您的服务人员弄乱了 /__/auth/... 下的页面,这些页面由 Firebase Auth 团队管理,需要完成签名-在。请从您的 Service Worker 缓存中删除该路径。
  • 是的。我在 serviceWorker 上看到了同样的问题。那是一个快速演示站点,所以我刚刚删除了演示的工作人员:) 问题是身份验证在 localhost 上不起作用。我的观点是它在 Firebase 托管上运行良好,但在 localhost 上运行不正常。
  • 无论是本地主机还是生产站点,设置都应该完全相同。如果您的示例应用无法正常运行,我将无法调试您的问题。
【解决方案2】:

我遇到了同样的问题,我的解决方案是在根 firebase.js 中有一个包含所有连接配置的文件:

// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
import {getAuth} from 'firebase/auth'

import { getAnalytics } from "firebase/analytics";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  apiKey: "xxxxxxx_xxx_R-xxx-CDxxxxcg",
  authDomain: "qxxxxxx-xxxx.firebaseapp.com",
  projectId: "xxxxxx-xxxxx",
  storageBucket: "xxxxxxx-xxxx.appspot.com",
  messagingSenderId: "xxxxxxx",
  appId: "1:xxxxxxx:wxb:xxxxxxxxxxxxxx",
  measurementId: "G-xxxxx"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);

export const db = getFirestore(app);
export const auth = getAuth(app);

【讨论】:

    猜你喜欢
    • 2019-11-22
    • 1970-01-01
    • 2021-12-20
    • 2018-06-04
    • 2022-10-13
    • 1970-01-01
    • 2021-11-03
    • 2015-01-02
    • 2018-01-25
    相关资源
    最近更新 更多