I'm trying to implement firebase in Sapper.
I installed the modules (@firebase/app
, @firebase/auth
, @firebase/firestore
) and then I wrote a configuration file:
import firebase from '@firebase/app';
import '@firebase/firestore'
import '@firebase/auth'
const config = {
// ...
};
// Initialize Firebase
firebase.initializeApp(config);
export { firebase };
// Initialize db
export const db = firebase.firestore();
export const auth = firebase.auth();
When I "npm run dev", I got an error saying that those firebase modules are intended only for client side and not for Node.js.
So, I tried to fix this problem in many ways and the only one that seems to work so far is using onMount
.
onMount(async () => {
const {auth} = await import('../firebase/config');
auth.signInWithEmailAndPassword("[email protected]", "test").then((res) => {
// do some stuff
})
})
Now it works, but I've 3 questions:
- is this the right way?
- should I remove those modules from server side or is better to keep them anyway?
- should I use both client side and server side versions of firebase and use client side one to retrieve all the data that are different for each visitor and server side to all the data in common?