绑定失败:SyntaxError:react native中的JSON输入意外结束



我在react本机项目中使用firebase。当我试图用电子邮件和密码注册用户时,这个错误是混合的。我使用窗口操作系统,并且仅和网格渲染

注意:我已经阅读了所有与此相关的问题,但没有任何帮助

newview以本地方式进行反应。请以正确的方式引导

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\node_modules\matro-cache\src\stores\FileStore.js:26:19)位于F:\React Native\ReactProjects\trailer-tracker\node_modules\matro-cache\src\cache.js:76:40位于Generator.next()步骤(F:\React Native\ReactProjects\trailer-tracker\node_modules\matro-cache\src\cache.js:18:30)位于F:\React Native\ReactProjects\trailer-tracker\node_modules\matro-cache\src\cache.js:37:14在new Promise()在F:\React Native\ReactProjects\trailer-tracker\node_modules\matro-cache\src\cache.js:15:12在Cache.get(F:\React Native\ReactProjects\trailer-tracker\node_modules\matro-Cache\src\Cache.js:102:7)位于F:\React Native\ReactProjects\trailer-tracker\node_modules\matro\src\DeltaBundler\Transformer.js:166:34BUNDLE〔android,dev〕/index.js 68.2%(947/1147),失败。

这是firebase中的另一个错误吗?

将非常感谢您的帮助

感谢

开始使用react native中的firebase。

添加firebase依赖

yarn add firebase

转到Firebase并创建一个新项目并转到部分将Firebase添加到您的web应用程序

为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);
});
}
}}

相关内容

  • 没有找到相关文章