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

Viewed 228

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.

1 Answers

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

Related