【发布时间】:2021-11-08 01:58:36
【问题描述】:
import * as admin from "firebase-admin";
import DataModel from "../types/firebase";
export class FirebaseManager {
db = admin.database();
constructor() {
this.db = admin.database();
if (this.db === undefined) {
throw "cannot find database";
}
let data = this.db
.ref(`/`)
.get()
.then((snapshot) => {
if (!snapshot.exists()) {
throw "no database found :(";
} else {
let data = snapshot.val();
try {
let castedData = data as DataModel;
console.log("Database successfully initialised!");
} catch {
throw "Data could not be casted properly during initialisation";
}
}
});
}
}
您好,我一直在开发一个需要 Firebase 作为后端的不和谐机器人。然而,当我初始化这个类时,调用 .get() 函数说Error: Error: Client is offline 但我一直在线,有人知道为什么吗?作为参考,我使用的是特定版本"firebase-admin": "^9.11.1"。如果您想查看所有代码,https://github.com/MaxiGames/MaxiGames.js/tree/firebase 在这里。
【问题讨论】:
标签: typescript firebase firebase-realtime-database offline firebase-admin