Jor*_*ton 6 javascript firebase firebase-tools google-cloud-firestore
对标题感到抱歉,我不确定这是否是我面临的正确问题,但是,我会尝试描述我正在尝试做的事情。
我已经更新了标题,因为其中的错误似乎是我的问题(原文:“模拟先行不保存文档?”)。
\n我有一个在产品上使用 Firebase 的 React 应用程序(函数、身份验证、firestore 和存储),我需要更改其中的一些内容,因此,我认为首先在本地进行这些更改然后部署它们会更安全。因此,我设置了 firebase 模拟器套件,并设置应用程序的环境变量以指向本地内容(应用程序的这一部分不需要存储,因此在本地未启用它)。
\n无论如何,我设置了一个本地身份验证帐户,以便我可以登录该帐户并将文档添加到“用户”集合中(这是需要的,因为应用程序会在 firestore 中查找登录用户的文档)但是,看起来当我刷新模拟器 UI 时,firestore 模拟器会删除此文档吗?
\n您可以在这个 GIF 中明白我的意思:Firestore 删除了文档
\n可能需要的其他信息:
\n\xe2\x9d\xaf firebase emulators:start --import ./functions/firestore --export-on-exit \ni emulators: Starting emulators: auth, functions, firestore\n! functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: database, hosting, pubsub, storage\n+ functions: Using node@12 from host.\ni firestore: Importing data from E:\\Project\\api\\functions\\firestore\\firestore_export\\firestore_export.overall_export_metadata\n! firestore: Did not find a Cloud Firestore rules file specified in a firebase.json config file.\n! firestore: The emulator will default to allowing all reads and writes. Learn more about this option: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration.\ni firestore: Firestore Emulator logging to firestore-debug.log\ni auth: Importing config from E:\\Project\\api\\functions\\firestore\\auth_export\\config.json\ni auth: Importing accounts from E:\\Project\\api\\functions\\firestore\\auth_export\\accounts.json\n! ui: Emulator UI unable to start on port 4000, starting on 4001 instead.\ni ui: Emulator UI logging to ui-debug.log\ni functions: Watching "E:\\Project\\api\\functions" for Cloud Functions...\n+ functions[us-central1-auth]: http function initialized (http://localhost:5001/my-project/us-central1/auth).\ni functions[us-central1-backup-scheduledFirestoreExport]: function ignored because the pubsub emulator does not exist or is not running.\n+ functions[us-central1-makeAdmin]: http function initialized (http://localhost:5001/my-project/us-central1/makeAdmin).\n+ functions[us-central1-users]: http function initialized (http://localhost:5001/my-project/us-central1/users).\n\n\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n\xe2\x94\x82 \xe2\x9c\x94 All emulators ready! It is now safe to connect your app. \xe2\x94\x82\n\xe2\x94\x82 i View Emulator UI at http://localhost:4001 \xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\n\n\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n\xe2\x94\x82 Emulator \xe2\x94\x82 Host:Port \xe2\x94\x82 View in Emulator UI \xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xa4\n\xe2\x94\x82 Authentication \xe2\x94\x82 localhost:9099 \xe2\x94\x82 http://localhost:4001/auth \xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xa4\n\xe2\x94\x82 Functions \xe2\x94\x82 localhost:5001 \xe2\x94\x82 http://localhost:4001/functions \xe2\x94\x82\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xbc\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xa4\n\xe2\x94\x82 Firestore \xe2\x94\x82 localhost:8080 \xe2\x94\x82 http://localhost:4001/firestore \xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xb4\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\xb4\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\n Emulator Hub running at localhost:4400\n Other reserved ports: 4500\n\nIssues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.\n
Run Code Online (Sandbox Code Playgroud)\n我觉得这是阻止我的问题,因为应用程序在控制台中产生错误
\n[2021-06-22T09:58:16.805Z] @firebase/firestore: Firestore (8.2.4): Could not reach Cloud Firestore backend. Backend didn\'t respond within 10 seconds.\nThis typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.\n
Run Code Online (Sandbox Code Playgroud)\n这是由线路引起的
\nawait firestore().doc(`users/${loggedInUser.uid}`).get();\n
Run Code Online (Sandbox Code Playgroud)\n我猜这是因为具有该 UID 的用户文档不存在(因为我似乎无法创建它)。
\n应用程序的环境和 firebase 初始化:
\nREACT_APP_FIREBASE_AUTH_DOMAIN=http://localhost:9099\nREACT_APP_FIREBASE_DATABASE_URL=http://localhost:8080\nREACT_APP_FIREBASE_PROJECT_ID=my-project\nREACT_APP_FIREBASE_STORAGE_BUCKET=my-project.appspot.com\nREACT_APP_FIREBASE_FUNCTIONS_ENDPOINT=http://localhost:5001/my-project/us-central1\n\n----- \n\nif (process.env.NODE_ENV !== \'production\') {\n console.log("USING LOCAL EMULATORS");\n firebase.auth().useEmulator(process.env.REACT_APP_FIREBASE_AUTH_DOMAIN);\n firebase.firestore().useEmulator(\'localhost\', 8080);\n firebase.functions().useEmulator(\'localhost\', 5001);\n\n firebase.firestore.setLogLevel(\'debug\');\n}\n
Run Code Online (Sandbox Code Playgroud)\nnode -v
:v12.0.0(这是产品正在运行的)
firebase --version
:9.13.1
任何帮助,将不胜感激。
\n编辑:即使通过函数添加用户也不起作用:
\n const userDoc = await admin\n .auth()\n .createUser({\n email: safeUser.email,\n password: safeUser.password,\n displayName: `${safeUser.firstName} ${safeUser.lastName}`,\n });\n \n delete safeUser.password;\n \n await admin.firestore().collection(\'users\').doc(userDoc.uid).set(safeUser);\n res.status(200).send(JSON.stringify({ uid: userDoc.uid, ...safeUser }));\n\n
Run Code Online (Sandbox Code Playgroud)\n这会返回用户
\n{\n "data": {\n "uid": "owLduAuMku520XVVm5J6qq92DPZp",\n "email": "test@test.com",\n "firstName": "Test",\n "lastName": "Account",\n "dob": "1900-01-01T00:00:00.000Z",\n "phoneNumber": "+447999999999"\n },\n "status": 200,\n "statusText": "OK",\n "headers": {\n "content-length": "224",\n "content-type": "text/html; charset=utf-8"\n },\n "config": {\n "url": "http://localhost:5001/my-project/us-central1/createUser",\n "method": "post",\n "data": "{\\"consent\\":true,\\"phoneNumber\\":\\"+447999999999\\",\\"dob\\":\\"1900-01-01T00:00:00.000Z\\",\\"password\\":\\"password\\",\\"email\\":\\"test@test.com\\",\\"firstName\\":\\"Test\\",\\"lastName\\":\\"Account\\"}",\n "headers": {\n "Accept": "application/json, text/plain, */*",\n "Content-Type": "application/json;charset=utf-8"\n },\n "transformRequest": [\n null\n ],\n "transformResponse": [\n null\n ],\n "timeout": 0,\n "xsrfCookieName": "XSRF-TOKEN",\n "xsrfHeaderName": "X-XSRF-TOKEN",\n "maxContentLength": -1,\n "maxBodyLength": -1\n },\n "request": {}\n}\n
Run Code Online (Sandbox Code Playgroud)\n但是,它仍然没有显示在模拟器 UI 中(它创建了 auth 用户)并且日志正常:
\ni functions: Beginning execution of "us-central1-createUser"\n! Received service account token ---- Assuming that it owns project "my-project".\n! Received service account token ---- Assuming that it owns project "my-project".\ni functions: Finished "us-central1-createUser" in ~2s\n
Run Code Online (Sandbox Code Playgroud)\n编辑 2:在模拟器 UI 上打开控制台,加载用户集合时,我看到与在应用程序上看到的相同错误:
\n[2021-06-22T11:44:56.597Z] @firebase/firestore: Firestore (8.5.0): Could not reach Cloud Firestore backend. Backend didn\'t respond within 10 seconds.\nThis typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.\n
Run Code Online (Sandbox Code Playgroud)\n编辑 3:似乎连接到端口 8080 处的 URL 暂时解决了此问题。转到单独选项卡中的频道 URL,然后允许 firebase 从中加载数据...更改端口可以解决问题吗?
\n编辑 4:更改端口没有解决问题。似乎是以下 URL 导致了该问题:
\nhttp://localhost:8081/google.firestore.v1.Firestore/Listen/channel?database=projects%2Fmy-project%2Fdatabases%2F(default)&VER=8&RID=rpc&SID=FgqppSIdbuIaPmABDJD6fA%3D%3D&CI=0&AID=0&TYPE=xmlhttp&zx=yzaslurbjssn&t=1\n
Run Code Online (Sandbox Code Playgroud)\n\n编辑 5:更新到最新的 firebase 模块没有帮助
\n好的,经过大量研究和环顾四周,添加似乎firebase.firestore().settings({ experimentalAutoDetectLongPolling: true });
解决了应用程序上的问题。它并不能解决用户界面的问题(我希望它能够工作,这样我就可以看到正在发生的事情),但是,我想我暂时可以忍受。
对于其他有同样问题的人,这是我的完整 firebase 配置:
if (process.env.NODE_ENV !== 'production') {
console.log("USING LOCAL EMULATORS");
firebase.auth().useEmulator(process.env.REACT_APP_FIREBASE_AUTH_DOMAIN);
firebase.firestore().useEmulator('localhost', 8081);
firebase.firestore().settings({ experimentalAutoDetectLongPolling: true }); //This seems to fix an issue with firestore emulator...
var storage = firebase.storage();
console.log("storage", storage);
storage.useEmulator("localhost", 9199);
firebase.functions().useEmulator('localhost', 5001);
firebase.firestore.setLogLevel('debug');
}
Run Code Online (Sandbox Code Playgroud)
如果有人知道为什么会这样,或者如何让模拟器 UI 正常工作,请告诉我们。我仍在寻找答案!
编辑:如果其他人在 Windows 上遇到同样的问题,请尝试 Linux!似乎在那里工作得很好!
归档时间: |
|
查看次数: |
872 次 |
最近记录: |