profile
viewpoint

Ask questionsWebstore instance lost on page refresh

I'm using vue js 2. I have a main file with this code:

 import Vue from 'vue'
 import App from './App.vue'
 import router from './router'

const Store = require('secure-webstore').Store

const store = new Store('user_data', 'lachiquichiqui89')

store.init().then(() => {
  // store is ready
})

Vue.prototype.$store = store

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')

This is working fine...I already store some data in indexeddb....but when I refresh the page, I think maybe the instance is lost, because I'm getting this error trying to get the store object inside a component:

Error: Master key not initialized
at Store.get key [as key] (secure-webstore.js?ee28:31)
at Store.eval (secure-webstore.js?ee28:87)
at Generator.next (<anonymous>)
at fulfilled (secure-webstore.js?ee28:4)

And data it's ok!!, so I don't know how to solve it...please help! cap

AKASHAorg/secure-webstore

Answer questions Master-Y0da

@deiu The error is showing up at this point:

   Vue.prototype.$store.get('user')
      .then(function(data){
            
        if(Object.entries(data.info).length === 0){
            data.info = {
               id: response.data.id,
                nombre: response.data.nombre,
                email: response.data.email,
                is_superuser: response.data.is_superuser
             }

              Vue.prototype.$store.set('user',  data)
              next()
            }

          })
          .catch(err => console.log(err))

This run without problems first time...but if the user reloads the page, gives the error.

useful!

Related questions

No questions were found.
source:https://uonfu.com/
Github User Rank List