Why I can't use firebase
onemanking opened this issue · 8 comments
I try to add these get data from Firebase realtime db in electron/main.ts
and never get the data from it
electron/main.ts
// Test active push message to Renderer-process.
win.webContents.on("did-finish-load", async () => {
const snapshot = await firebase.database().ref("version").get(); // **it not work**
const version = snapshot.val() as string; // **never reach to this point**
console.log(`Version: ${version}`);
});
but if I use it in the render process, it will work
App.tsx
function App() {
const firebaseApp = firebase.initializeApp(firebaseConfig);
const db = firebaseApp.database();
const versionRef = db.ref("version");
const [version, setVersion] = useState("0.0.0");
useEffect(() => {
versionRef.get().then((snapshot) => setVersion(snapshot.val() as string)); // **it's work!**
});
return (
<div className="App">
<h1>Version: {version}</h1>
</div>
)
}
Do I need to set up or config something? Thank you
I not sure what you wath.
The following line is not outputting log in your App?
// Test active push message to Renderer-process.
win.webContents.on("did-finish-load", async () => {
const snapshot = await firebase.database().ref("version").get(); // **it not work**
const version = snapshot.val() as string; // **never reach to this point**
+ console.log(`Version: ${version}`);
});
It's just for testing purposes.
And yes, nothing happens after await to get the data.
and if I create a project in another way. like using npm init electron-app@latest my-new-app -- --template=webpack-typescript
the firebase code in main.ts
will work.
Can you provide a minimal reproduction repo?
Can you provide a minimal reproduction repo?
https://github.com/onemanking/electron-vite-firebase
here you go
it only log for firebase object. You should try to access to database or another function and see if it works
This requires using a firebase account, I do not have a firebase account available.