Event listener 'snipcart.ready' not working

Hi !

I am developing an ecommerce website on nuxt.js (based on vue.js)

When my default layout is mounted i try to check if an user is connected but even if it is the response is always ‘signout’, but when i put my code in a settimeout with a bit of time it’s working, any idea why the event is not triggering right ?

Thanks by advance !

mounted() {
  document.addEventListener('snipcart.ready', function() {
    const customer = Snipcart.store.getState().customer
    console.log(customer)
  })
}

Be sure to ad a “;” at the end of the command. I don’t know it that solves the problem, but it can’t hurt.

  }) ;
}

Ok simple solution (switch from mounted to created idk if its really better but you need to be on client side rendering because you can’t access “document” on the server when using nuxt)

created() {
  document.addEventListener('snipcart.ready', () => {
    Snipcart.events.on('snipcart.initialized', () => {
      console.log(Snipcart.store.getState().customer)
    });
  })
}