buhrmi / vue-pouch

Live and reactive PouchDB bindings for Vuejs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to use with vuex ?

DamienFriot opened this issue · comments

commented

Sorry for a year old answer. But maybe someone else might need it :-)

This is one solution I've got working last nite. Still having some issues with it. But maybe we can help each other?

export default new Vuex.Store({

  state: {
    isAuth: false
  },

  mutations: {
    auth: (state, val) => {
      state.isAuth = val
    },
  },

  actions: {

    session ({ commit }) {
      return new Promise (resolve => {
        db.getSession((err, response) => {
          if (response.userCtx.name) commit('auth', true)
          else commit('auth', false)

          resolve()
        })
      })
    },

    signIn ({ commit }, data) {
      return new Promise (resolve => {
        db.logIn(data.email, data.pass, (err, response) => {
          if (response.ok && !err) commit('auth', true)
          else commit('auth', false)

          resolve()
        })
      })
    },

    signOut ({ commit }, data) {
      return new Promise (resolve => {
        db.logOut((err, response) => {
          if (!err) commit('auth', false)
          resolve()
        })
      })
    },

  }

})