我正在尝试从我的应用程序调用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:权限被拒绝”
我想这是因为我没有通过身份验证。我的问题如何禁用仿真器的身份验证?
1条答案
按热度按时间iqjalb3h1#
这可能是你的规则造成的。你需要更新你的
firestore.rules
,搜索文件并更新它;