在本机反应中从 android 模拟器连接到模拟器上的云功能 运行
Connecting to cloud function running on emulator from android emulator in react native
我正在构建一个应用程序并在后端使用 firebase。我使用 react-native-firebase 在我的应用程序中使用 firebase。我开发了登录云功能
exports.login = functions.https.onCall((data, context) => {
console.log("data", data);
console.log("context", context);
return "Login successful";
});
在 运行ning npm 运行 serve in the functions 文件夹中,我在我的控制台中获取这些配置。
Console output after running npm run serve inside functions folder for firebase
我还添加了以下代码以从我的 android 模拟器 运行 应用程序连接到云功能。
import functions from "@react-native-firebase/functions"
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const handleLogin = () => {
// console.log(email, password);
functions()
.useFunctionsEmulator("URL")
.httpsCallable("login")({ email, password })
.then((response) => {
alert(response);
});
}
for URL 我试过“http://localhost:5001/”,因为它是功能模拟器正在侦听的端口
Port on which cloud functions is listening。但是在 运行ning 应用程序时我收到了这个错误
Error on clicking login button in app console。我尝试搜索错误,但没有找到任何相关信息。任何帮助将不胜感激。
这些是我定义的云函数
exports.helloWorld = functions.https.onRequest((request, response) => {
functions.logger.info("Hello logs!", { structuredData: true });
response.send("Hello from Firebase!");
});
exports.signup = functions.https.onRequest((request, response) => {
console.log("request", request);
response.send("SignUp successfull");
});
exports.login = functions.https.onCall((data, context) => {
console.log("data", data);
console.log("context", context);
return "SignIn successfull";
});
终于搞定了
const handleLogin = async () => {
functions().useFunctionsEmulator("http://localhost:5001")
const response = await functions().httpsCallable("login")({ email, password });
console.log("response", response);
}
这是从您的 运行 android 模拟器在模拟器内部成功调用本地云函数所需的所有代码。
我正在构建一个应用程序并在后端使用 firebase。我使用 react-native-firebase 在我的应用程序中使用 firebase。我开发了登录云功能
exports.login = functions.https.onCall((data, context) => {
console.log("data", data);
console.log("context", context);
return "Login successful";
});
在 运行ning npm 运行 serve in the functions 文件夹中,我在我的控制台中获取这些配置。 Console output after running npm run serve inside functions folder for firebase
我还添加了以下代码以从我的 android 模拟器 运行 应用程序连接到云功能。
import functions from "@react-native-firebase/functions"
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const handleLogin = () => {
// console.log(email, password);
functions()
.useFunctionsEmulator("URL")
.httpsCallable("login")({ email, password })
.then((response) => {
alert(response);
});
}
for URL 我试过“http://localhost:5001/”,因为它是功能模拟器正在侦听的端口 Port on which cloud functions is listening。但是在 运行ning 应用程序时我收到了这个错误 Error on clicking login button in app console。我尝试搜索错误,但没有找到任何相关信息。任何帮助将不胜感激。
这些是我定义的云函数
exports.helloWorld = functions.https.onRequest((request, response) => {
functions.logger.info("Hello logs!", { structuredData: true });
response.send("Hello from Firebase!");
});
exports.signup = functions.https.onRequest((request, response) => {
console.log("request", request);
response.send("SignUp successfull");
});
exports.login = functions.https.onCall((data, context) => {
console.log("data", data);
console.log("context", context);
return "SignIn successfull";
});
终于搞定了
const handleLogin = async () => {
functions().useFunctionsEmulator("http://localhost:5001")
const response = await functions().httpsCallable("login")({ email, password });
console.log("response", response);
}
这是从您的 运行 android 模拟器在模拟器内部成功调用本地云函数所需的所有代码。