我是firebase的新手,我正在尝试创建一个利用用户身份验证的简单应用程序.在项目的这一点上,我尝试使用CLI命令在本地服务器上运行firebase.
我已经设置了firebase init和firebase部署.当我在我的项目文件夹中键入firebase serve时,我得到了响应,
"发生意外的错误".
下面我附上我的firebase-debug.log文件的内容.任何帮助,将不胜感激.谢谢
命令需要范围:
["email","openid"," https://www.googleapis.com/auth/cloudplatformprojects.readonly "," https://www.googleapis.com/auth/firebase ",... [debug] [ 2017-06-11T17:09:09.607Z]>通过登录用户授权
TypeError:无法读取未定义的属性"public"
我尝试使用命令行functions:config:unset es.tipsinstitue.type,因为这里给出了环境配置.但这对我不起作用.它给了我以下例外.
The filename, directory name or volume label syntax is incorrect.
Run Code Online (Sandbox Code Playgroud)
请帮我.
目前,我们正在在线模式下使用“firebase-functions-test”来测试我们的 firebase 功能(如此处所述 https://firebase.google.com/docs/functions/unit-testing),我们设置如下:
//setupTests.ts
import * as admin from 'firebase-admin';
const serviceAccount = require('./../test-service-account.json');
export const testEnv = require('firebase-functions-test')({
projectId: 'projectId',
credential: admin.credential.cert(serviceAccount),
storageBucket: 'projectId.appspot.com'
});
const testConfig = {
dropbox: {
token: 'dropboxToken',
working_dir: 'someFolder'
}
};
testEnv.mockConfig(testConfig);
// ensure default firebase app exists:
try {
admin.initializeApp();
} catch (e) {}
Run Code Online (Sandbox Code Playgroud)
我们希望在我们的测试中不再针对实际的 firestore 实例进行测试,而是使用模拟器。
我在网上找到的文档、问题和示例要么已经过时,要么描述了如何设置模拟器以测试安全规则或 Web 前端。
尝试使用 firebase.initializeAdminApp({ projectId: "my-test-project" });没有成功。
我也试过设置 FIRESTORE_EMULATOR_HOST=[::1]:8080,127.0.0.1:8080
所以问题是:如何在我的测试中初始化 firebaseApp,以便我的功能连接到 firestore 模拟器?
firebase firebase-tools google-cloud-functions google-cloud-firestore
启动模拟器时,我在实时数据库模拟器中看到 2 个数据库。一个与<project id>另一个<project id>-default-rtdb。
有人可以解释或参考一些文档来解释为什么会这样吗?
这是我的设置文件
firebase.json
{
"database": {
"rules": "database.rules.json"
},
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
],
"source": "functions"
},
"emulators": {
"auth": {
"port": 9099
},
"functions": {
"port": 5001
},
"database": {
"port": 9000
},
"pubsub": {
"port": 8085
},
"ui": {
"enabled": true
}
}
}
Run Code Online (Sandbox Code Playgroud)
函数/package.json
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"serve": "npm …Run Code Online (Sandbox Code Playgroud) 我正在运行 firebase 模拟器。
我的应用程序可以调用 firebase 云函数,如果允许用户(取决于数据库中的值),该函数可以创建自定义用户声明
我正在尝试调用该函数:
import * as firebase from '@firebase/testing';
import * as fs from 'fs';
const app = firebase.initializeTestApp({
databaseName: 'mydb',
auth: {
uid: 'useruid'
},
});
describe('Firebase Functions', () => {
beforeEach(async () => {
await firebase.loadDatabaseRules({
databaseName: 'mydb',
rules: fs.readFileSync('database.rules.json', 'utf8'),
});
});
afterAll(async () => {
await Promise.all(firebase.apps().map((app) => app.delete()));
});
const cloudfunction = app.functions().httpsCallable('cloudfunction')
it('throws error if user is not authenticated', async () => {
await firebase.assertFail(cloudfunction())
})
});
Run Code Online (Sandbox Code Playgroud)
这是抛出一个错误:
错误:错误:预检响应具有无效的 HTTP …
javascript firebase-tools firebase-authentication google-cloud-functions
我几周前已更新到 Firebase v9,在尝试将我的 Firebase 应用程序连接到 Firestore 模拟器时遇到问题。
firebase.js(我的 VueJS 插件,我在其中设置 Firebase):
import { initializeApp, getApps } from "firebase/app"
import { getAuth, connectAuthEmulator, onAuthStateChanged } from "firebase/auth";
import { getFirestore, connectFirestoreEmulator } from "firebase/firestore"
import { getStorage, connectStorageEmulator } from "firebase/storage";
import { getFunctions, connectFunctionsEmulator } from 'firebase/functions';
import { isSupported, getAnalytics } from "firebase/analytics";
export default async ({ app }, inject) => {
const firebaseConfig = {
apiKey: process.env.FIREBASE_API_KEY,
authDomain: process.env.FIREBASE_AUTH_DOMAIN,
databaseURL: process.env.FIREBASE_DATABASE_URL,
projectId: process.env.FIREBASE_PROJECT_ID,
storageBucket: process.env.FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.FIREBASE_MESSAGING_SERVICE_ID,
appId: …Run Code Online (Sandbox Code Playgroud) firebase vue.js firebase-tools nuxt.js google-cloud-firestore
当。。。的时候firebase emulator:start在我的 vscode powershell 终端中运行时,一些 java.exe 窗口会弹出。一切都很好。
当我使用 ctrl+c 命令关闭 firebase 模拟器时,终端中的日志表明一切都应该正常关闭。这是之后的日志^C:
i emulators: Received SIGINT (Ctrl-C) for the first time. Starting a clean shutdown.
i emulators: Please wait for a clean shutdown or send the SIGINT (Ctrl-C) signal again to stop right now.
i Automatically exporting data using --export-on-exit "./data" please wait for the export to finish...
Terminate batch job (Y/N)? i Found running emulator hub for project une-petite-partie at http://localhost:4400
i Deleting directory C:\Users\schar\Documents\Programming\Projects\Card …Run Code Online (Sandbox Code Playgroud) 我正在使用 firebase 模拟器来运行测试,并且收到了有关使用缓存系统进行优化的警告。
我怎样才能做到这一点?
看起来您正在 CI 环境中运行。您可以通过缓存 /home/runner/.cache/firebase/emulators 目录来避免重复下载 Firestore 模拟器。
我正在尝试在新的 Firebase 云存储模拟器中创建额外的存储桶。我在 EmulatorUI 中没有看到任何选项,也没有在网上找到任何资源。这可能吗?
我正在尝试使用 Firebase 客户端 sdk 编写一些自动化测试。这些测试应该使用 Firebase Auth 模拟器。为了避免搞乱生产数据,我使用带有演示项目 ID 的模拟器(如文档中所述)。
我使用以下命令启动模拟器:
firebase emulators:start --project demo-test --only functions,firestore,storage,auth
Run Code Online (Sandbox Code Playgroud)
然后在我的测试中,我使用以下命令初始化应用程序:
import { initializeApp } from 'firebase/app'
import { getAuth, connectAuthEmulator } from 'firebase/auth'
const app = initializeApp({ projectId: 'demo-test' })
const auth = getAuth(app)
connectAuthEmulator(auth, 'http://localhost:9099')
Run Code Online (Sandbox Code Playgroud)
当测试初始化时,我收到此错误:
FirebaseError: Firebase: Error (auth/invalid-api-key).
> 45 | const auth = getAuth(app)
| ^
Run Code Online (Sandbox Code Playgroud)
注意:此问题仅在身份验证时发生。我可以成功连接到 Firestore 等其他模拟器。
看来,不管文档怎么说,我实际上无法将客户端 SDK 连接到演示项目并使用 auth 模拟器。每次我尝试时,都会抛出此错误。
有人知道如何设置演示项目模拟器并将客户端 SDK 连接到身份验证模拟器吗?