In my vuejs-nuxt project using SSR mode, I encountered an issue when trying to call a socket event. I need to pass the userID to the socket from the store. The GetUserUUID getter functions properly in all other APIs except when called from the "plugin/socketio.js" file. I am seeking assistance on how to retrieve 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']
},
https://i.sstatic.net/ip1Ii.png
This image shows the result of console.log(store.getters), however, I specifically need to access GetUserUUID.