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";
}
}
});
}
}
Hello there, I've been building a Discord bot that relies on Firebase for the backend. However, when initializing this class, an error occurs when calling the .get() function saying Error: Error: Client is offline
. I know for a fact that I am online, so why is it showing this message? Just to give you context, I'm using version
"firebase-admin": "^9.11.1"
. If you would like to view all of the code, it's available at https://github.com/MaxiGames/MaxiGames.js/tree/firebase
.