Giter VIP home page Giter VIP logo

Comments (4)

mesqueeb avatar mesqueeb commented on June 15, 2024

Dear David Piesse,
Thank you for your comment!
In line with my vuex plugins:

I'm currently working on a vuex-easy-firebase-auth plugin to easily setup the firebase authentication and have it saved in a vuex user module.

However, that package needs some more time until it's ready for beta release. : S

I do think that maybe I need some better documentation here as well for how to enable the firestore.

For now you I'll share you how I personally do it in my projects:

// enable firestore with persistence
async function getFirestore () {
  const firestore = Firebase.firestore()
  firestore.settings({timestampsInSnapshots: true})
  try {
    await firestore.enablePersistence()
  } catch (err) {
    console.log('err.code → ', err.code)
    if (err.code === 'failed-precondition') {
      // Multiple tabs open, persistence can only be enabled in one tab at a a time.
      let message = store.getters.text.api['firebase/failed-precondition']
      notify({message, preset: 'error'})
    } else if (err.code === 'unimplemented') {
      // The current browser does not support all of the
      // features required to enable persistence
      return firestore
    }
  }
  return firestore
}

// =========>
// Start Firebase
// =========>
Firebase.initializeApp(firebaseConfig)
Firebase.auth().onAuthStateChanged(user => {
  getFirestore().then(db => {
    if (user) {
      // Signed in. Let Vuex Easy Firestore know.
      store.dispatch('module/path/openDBChannel') // open the DB channels
    } else {
      // Signed out. Let Vuex know.
      store.dispatch('resetStore', null)
    }
  })
})

from vuex-easy-firestore.

davidpiesse avatar davidpiesse commented on June 15, 2024

Awesome!
Thanks for spending the time with a full reply; I look forward to the next package!

I had a play last night and I had a simpler version of your method; which is great as I know am on the right path.

from vuex-easy-firestore.

mesqueeb avatar mesqueeb commented on June 15, 2024

@davidpiesse No problem!

Let me know if you are able to use this package well or run into any problems! I'll try help out as much as I can!
For now this plugin works for me. (However, I still need to add tests, but having trouble finding a good Firestore mock for testing...)

It's crucial to not forget to open the DB channel: dispatch('module/path/openDBChannel')

Please note I haven't tested when a user logs out and a different user logs in yet. I need to finish auto re-freshing the vuex store in that case, so for now you'd have to do something like dispatch('resetStore') and write this yourself. Just empty out the prop where you save your docs should be fine.

I'm still working on perfecting the integration with vuex-easy-access have a look at that library as well and let me know what you think : D

from vuex-easy-firestore.

davidpiesse avatar davidpiesse commented on June 15, 2024

Will do.
I'll open issues if I find things but just because it's an easy way to communicate on these things.
I'll try and push fixes if I can 😁

from vuex-easy-firestore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.