TransWikia.com

Vuejs-nuxt (SSR Mode) not able to get UserUUID through getter inside plugins. It shows undefined for GetUserUUID

Stack Overflow Asked by Ritesh Naik on January 10, 2021

I’m using SSR mode in my vuejs-nuxt project. So whenever I attempt to call socket event, I need to pass userID to that socket from the store. The GetUserUUID getter works fine in all other APIs. But it fails only in case of calling from the "plugin/socketio.js" file. I need some help to get data from the getter.

plugins/socketio.js

export default async ({ store, $axios }) => {
   console.log(store.getters.GetUserUUID,"Current User UUID which is showing undefined");

function listenStock({ channelName, eventName }, callback) {
console.log("callback",callback);
window.Echo.channel(channelName).listen(eventName, callback);
}

//Fetch user data
listenStock(
 {
  channelName: `BalanceUpdateEvent.${store.getters.GetUserUUID}`,
  eventName: "BalanceUpdateEvent"
 },
 ({ data }) => {
   console.log(data, "socket data");
   try {
     store.dispatch("setUserBalance", data.data.userBalance);
   } catch (ex) {
     console.log(ex);
   }
 }
);

nuxt.config.js

plugins: [
  { src: '~/plugins/socketio', mode: 'client' }
]
echo: {
   plugins: ['~/plugins/socketio.js']
},

This image is a result of console.log(store.getters), But I need to access GetUserUUID.

One Answer

Please try it in the nuxt.config.js

export default {
  plugins: [
    ....
    { src: '~/plugins/socketio.js', mode: 'client' }, // only on client side
    ...
  ]
}

That run your plugin in client side

Answered by soroush on January 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP