android - 从反应原生的android模拟器连接到模拟器上运行的云功能
问题描述
我正在构建一个应用程序并使用 firebase 作为后端。我使用react-native-firebase在我的应用程序中使用 firebase。我开发了登录云功能
exports.login = functions.https.onCall((data, context) => {
console.log("data", data);
console.log("context", context);
return "Login successful";
});
在功能文件夹中运行 npm run serve 时,我在控制台中获取了这些配置。 在firebase的functions文件夹中运行npm run serve后的控制台输出
我还添加了以下代码,以从运行应用程序的 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);
});
}
对于 URL,我尝试了“http://localhost:5001/”,因为它是函数模拟器正在侦听的 端口 云函数正在侦听的端口。但是在运行应用程序时,我收到此错误 Error on click 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 模拟器在模拟器中本地成功调用云函数所需的所有代码。
推荐阅读
- c# - 从 Web 异常调用 WCF
- bash - 来自 CLI 的 Rocket 聊天消息
- android - 如何使用 sqlite 创建 kotlin 登录?
- java - String.getBytes() 比 charset.encode 快
- android - AppWidget RemoteView Factory 从领域数据库返回错误数据
- javascript - 确定打字稿中可能有多种类型的参数类型
- swift - 如何在另一个应用程序iOS swift中将应用程序用作模块
- django - django-filter 在查询外键项时显示模型对象
- svg - 为什么元素会出现在嵌套 svg 元素的视图框之外?
- sql - 从原始 SQL 到 Pojos 的 jOOQ 映射记录