我在反应本地项目中使用 firebase 。当我尝试使用电子邮件和密码注册用户时,就会出现此错误。 我正在使用窗口操作系统,并且仅使用 andorid渲染
注意:我已经阅读了与此相关的所有问题,但无济于事
新手以正确的方式响应本地.please指南
package.json
"firebase": "^5.8.2",
"native-base": "^2.11.0",
"react": "16.6.3",
"react-native": "^0.57.8",
"react-native-elements": "^0.19.1",
"react-native-firebase": "^5.2.2",
"react-native-gesture-handler": "^1.0.15",
"react-native-maps": "^0.23.0",
"react-native-svg": "^8.0.10",
"react-native-vector-icons": "^6.2.0",
"react-navigation": "^3.2.1"
注册代码
import * as firebase from 'firebase'
//Intiazlize firebase
const firebaseConfig = {
apiKey: "AIzaSyCUK5QkcvTcvfCKlbwnnI8GskIgcLGMcqA",
authDomain: "trailertracker-da09c.firebaseapp.com",
databaseURL: "https://trailertracker-da09c.firebaseio.com",
projectId: "trailertracker-da09c",
storageBucket: "",
}
firebase.initializeApp(firebaseConfig)
signUpUser = (email,password) => {
try{
if(this.state.password.length < 6 ){
alert("Please Enter Valid Email and Password")
return
}
firebase.auth().createUserWithEmailAndPassword(email,password)
} catch(err){
console.log(err)
}
}
完全错误是
已完成加载依赖关系图。错误:捆绑失败:SyntaxError: JSON输入意外结束 在JSON.parse() 在FileStore.get(F:\ React Native \ ReactProjects \ trailer-tracker \ TrailerTracker \ node_modules \ metro-cache \ src \ stores \ FileStore.js:26:19) 在F:\ React Native \ ReactProjects \ trailer-tracker \ TrailerTracker \ node_modules \ metro-cache \ src \ Cache.js:76:40 在Generator.next() 在步骤(F:\ React Native \ ReactProjects \ trailer-tracker \ TrailerTracker \ node_modules \ metro-cache \ src \ Cache.js:18:30) 在F:\ React Native \ ReactProjects \ trailer-tracker \ TrailerTracker \ node_modules \ metro-cache \ src \ Cache.js:37:14 在新的Promise() 在F:\ React Native \ ReactProjects \ trailer-tracker \ TrailerTracker \ node_modules \ metro-cache \ src \ Cache.js:15:12 在Cache.get(F:\ React Native \ ReactProjects \ trailer-tracker \ TrailerTracker \ node_modules \ metro-cache \ src \ Cache.js:102:7) 在F:\ React Native \ ReactProjects \ trailer-tracker \ TrailerTracker \ node_modules \ metro \ src \ DeltaBundler \ Transformer.js:166:34 BUNDLE [android,dev] ...... / index.js 68.2%(947/1147),失败。
这是Firebase中的另一个错误还是错误?
我们将非常感谢您的帮助
谢谢
答案 0 :(得分:0)
要开始在React Native中使用Firebase。
添加Firebase依赖项
yarn add firebase
转到 Firebase 并创建一个新项目,然后转到该部分 将Firebase添加到您的网络应用
像这样为Firebase的配置创建一个类
import firebase from "@firebase/app";
require("firebase/database");
require("firebase/storage");
require("firebase/auth");
let config = {
apiKey: "YOUR PROJECT apiKey",
authDomain: "YOUR PROJECT authDomain",
databaseURL: "YOUR PROJECT databaseURL",
projectId: "XXXXXXXX",
storageBucket: "",
messagingSenderId: "XXXXXXXXXX",
appId: "XXXXXXXXXXXXXXXXXXXXXXXX"
};
export default class DBHandler {
static auth;
static database;
static init() {
firebase.initializeApp(config);
DBHandler.database = firebase.database();
DBHandler.auth = firebase.auth();
}
}
App.js 中的初始化Firebase
import DBHanlder from "./src/api/constants";
export default class App extends Component {
componentDidMount = () => {
DBHanlder.init();
};
render() {
return <YourApp />;
}
}
您已经完成了初始化部分。现在您可以像下面那样使用 auth
import DBHandler from "../api/constants";
class Login extends Component {
signinUser = () => {
DBHandler.auth.signInWithEmailAndPassword(email, password)
.then(() => {
//Do what you want
})
.catch((error) => {
//handle error
var errorCode = error.code;
var errorMessage = error.message;
alert(errorMessage);
console.log("ERROR");
console.log(errorCode, errorMessage);
});
}
}}