我正在使用expo管理的工作流,当我尝试使用Firebase模拟器套件时,我总是会遇到这个Firebase错误。我试过几件事,但我就是无法将我的项目(我使用的是Android模拟器(连接到模拟器套件。
这是我的火球实例;
import firebase from "firebase/app";
import "firebase/firestore";
import "firebase/auth";
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: "",
};
!firebase.apps.length ? firebase.initializeApp(firebaseConfig) : firebase.app();
export const db = firebase.firestore();
export const auth = firebase.auth();
if (__DEV__) {
db.settings({
host: "localhost",
ssl: false,
});
auth.useEmulator("http://localhost:9099");
}
export default firebase;
这是身份验证部分
import { auth, db } from "./firebase";
const regUsers = async (userCred) => {
try {
const user = await auth.createUserWithEmailAndPassword(
userCred.email,
userCred.password
);
if (user) {
const currentUser = auth.currentUser.uid;
try {
await db.collection("users").doc(currentUser).set({
name: userCred.name,
email: userCred.email,
matricNumber: userCred.matricNumber,
dateCreated: new Date(),
});
} catch (error) {
console.log(
"Something went wrong while saving user credentials",
error
);
}
return user;
}
} catch (error) {
console.log("Something went wrong while registering user", error);
}
};
const loginUser = async (userCred) => {
try {
const result = await auth.signInWithEmailAndPassword(
userCred.email,
userCred.password
);
if (result) {
const currentUser = auth.currentUser.uid;
return currentUser;
}
} catch (error) {
console.log("Something went wrong while login user", error);
}
};
export default {
regUsers,
loginUser,
};
每当我尝试登录或注册用户时,我都会收到错误。有人知道我还能试什么吗。只有当我尝试连接到模拟器时才会出现错误,而我所在的地方的互联网连接很糟糕。我在firestore调试日志中还注意到了这个警告。"io.gapi.emulators.nety.HttpVersionRoutingHandler通道读取信息:检测到非HTTP/2连接。
显然,当您使用模拟器时,应该将localhost替换为10.0.2:8080,它应该可以正常工作。