Ad
Firebase Not Initialized In Vue3 Router
I initialize firebase in main.js and it works overall in the application.
When I use a firebase in the router for the beforeEnter
checks it doesn't recognize that firebase has been initialized.
exception: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
Looking at logs, the router beforeEnter
check is done before main.js where the init is done.
main.js:
firebase.initializeApp(firebaseConfig);
firebase.auth().onAuthStateChanged(function(user){...}
router.ts:
router.beforeEach((to, from, next) => {
console.log("router | beforeEach")
const currentUser = firebase.auth().currentUser;
const requiresAuth = to.matched.some(record => record.meta.requiresAuth);
if(requiresAuth && (!currentUser || currentUser.isAnonymous)) next('login')
else if(!requiresAuth && currentUser) next('eorDashboard')
else next();
})
How to bypass this issue as it was working well in Vue2?
Ad
Answer
In your main.js
, you should make sure only init Vue application when Firebase Auth object is ready to use
main.js
let app = ''
firebase.initializeApp(firebaseConfig);
firebase.auth().onAuthStateChanged(() => {
if (!app) {
app = new Vue({
router,
render: h => h(App)
}).$mount('#app')
}
})
Ad
source: stackoverflow.com
Related Questions
- → How can I query Firebase for an equalTo boolean parameter?
- → How can I access nested data in Firebase with React?
- → Firebase simple blog (confused with security rules)
- → Removing item in Firebase with React, re-render returns item undefined
- → AngularJS Unknown Provider Error (Firebase & AngularFire)
- → How do you pass top level component state down to Routes using react-router?
- → "this" is null in firebase query function in reactjs
- → Angular Module Failed to Load
- → Multiple dex files define Lcom/google/android/gms/internal/zzrx;
- → Joining Firebase tables in React
- → How can I make add firepad to my reactjs project?
- → How to use Cloud Functions for Firebase to prerender pages for SEO?
- → React.js component has null state?
Ad