FirebaseError: permission-denied Firebase Functions /如何在模拟器中



我正在尝试从我的应用程序调用firebase函数。我正在使用firestore和函数模拟器与firebase emulators:start

这是我的云函数:

import * as functions from "firebase-functions";
export const helloWorld = functions.https.onRequest((request, response) => {
response.send({"text":"Hello from Firebase!"});
});

这就是我如何从我的expo go应用程序调用函数。

import { StyleSheet, Text, View } from 'react-native';
import {initializeApp} from 'firebase/app';
import {getFirestore, connectFirestoreEmulator } from "firebase/firestore";
import {getFunctions, connectFunctionsEmulator, httpsCallable} from "firebase/functions";
import {useState} from "react";
initializeApp({
apiKey: "AIzxxxxxxxxxxxxxxxxxxxBbBFNGMI",
authDomain: "sixxxxxxxxxcc8.firebaseapp.com",
projectId: "sxxxxxxxxxxx8",
storageBucket: "xxxxxxxxxxxxxcc8.appspot.com",
messagingSenderId: "6xxxxxxxxxx",
appId: "1:65xxxxxxxx13:web:d0exxxxxxxxxxxxxxxxx7c"
});
const db = getFirestore();
const functions = getFunctions();
connectFirestoreEmulator(db, "localhost", 8080 )
connectFunctionsEmulator(functions, "localhost", 5000 )
const addMessage = httpsCallable(functions, 'helloWorld');
export default function App() {
const [result, setResult] = useState("")
addMessage({ text: "text" })
.then((result) => {
// Read result of the Cloud Function.
/** @type {any} */
const data = result.data;
const sanitizedMessage = data.text;
setResult(sanitizedMessage)
}).catch(console.log);
return (
<View style={styles.container}>
<Text>{result}</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});

我总是得到"FirebaseError: permission-denied">

我相信这是因为我没有被认证。我的问题如何禁用模拟器的身份验证?

这可能是您的规则造成的。您将需要更新您的firestore.rules,搜索文件并使用以下命令更新它;

rules_version = 2
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: true;
}
}
}

相关内容

  • 没有找到相关文章

最新更新