嘿,我刚开始使用电子 js 并尝试连接到 firebase,我在typescript中使用 react。
当我尝试从 firebase 读取数据时,出现错误
我在以下链接中的 firebase 文档中尝试了该方法https://firebase.google.com/docs/firestore/quickstart
Error: A backoff operation is already in progress.
at ExponentialBackoff.backoffAndWait (D:\projects\vugha\Membership\app\node_modules\@google-cloud\firestore\build\src\backoff.js:164:35)
at Firestore._retry (D:\projects\vugha\Membership\app\node_modules\@google-cloud\firestore\build\src\index.js:977:31)
Caused by: Error
at Firestore.getAll (D:\projects\vugha\Membership\app\node_modules\@google-cloud\firestore\build\src\index.js:755:23)
at DocumentReference.get (D:\projects\vugha\Membership\app\node_modules\@google-cloud\firestore\build\src\reference.js:199:32)
at Home._this.loginClick (http://localhost:1212/dist/renderer.dev.js:1355:40)
at HTMLUnknownElement.callCallback (http://localhost:1212/dist/renderer.dev.js:2564:14)
at Object.invokeGuardedCallbackDev (http://localhost:1212/dist/renderer.dev.js:2613:16)
at invokeGuardedCallback (http://localhost:1212/dist/renderer.dev.js:2668:31)
at invokeGuardedCallbackAndCatchFirstError (http://localhost:1212/dist/renderer.dev.js:2682:25)
at executeDispatch (http://localhost:1212/dist/renderer.dev.js:2765:3)
at executeDispatchesInOrder (http://localhost:1212/dist/renderer.dev.js:2790:5)
at executeDispatchesAndRelease (http://localhost:1212/dist/renderer.dev.js:5654:5)
但是我可以将数据写入 firebase,任何关于我遗漏的地方的想法
/* eslint-disable promise/always-return */
/* eslint-disable @typescript-eslint/ban-types */
/* eslint-disable react/destructuring-assignment */
/* eslint-disable react/no-unused-state */
/* eslint-disable prettier/prettier */
import React from 'react';
import { Link } from 'react-router-dom';
import routes from '../constants/routes.json';
import styles from './Home.css';
const admin = require('firebase-admin');
const serviceAccount = require('../marinamembers-dd141799d80d.json');
if (!admin.apps.length) {
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
}
class Home extends React.Component<{},any>{
constructor(props) {
super(props);
this.state = {
username: '',
password: '',
alertText: '',
};
}
loginClick = () => {
const db = admin.firestore();
db.collection('users').doc('hi').get().then((userData) => {
console.log(userData.data);
}).catch((e) => {
console.log(e);
});
}
render(){
let inputStyle = { opacity: '0' };
if(this.state.alertText !== ''){
inputStyle = { opacity: '1' };
}
return (
<div className={styles.home}>
<div style={inputStyle} className={styles.alert}>
<div>{this.state.alertText}</div>
<span>×</span>
</div>
<div className={styles.main}>
<div className={styles.container} data-tid="container">
<h2>Home</h2>
<Link to={routes.COUNTER}>by Vugha Technologies</Link>
</div>
<div className={styles.login} data-tid="login">
<h2>Login</h2>
<input onChange={(event) => {this.setState({username: event.target.value});}} type="text" id="loginName" name="loginName" placeholder="User Name" />
<input onChange={(event) => {this.setState({password: event.target.value});}} type="password" id="loginPassword" name="loginPassword" placeholder="Password" />
<button onClick={this.loginClick} type="button">Login</button>
</div>
</div>
</div>
);
}
}
export default Home;