wixRealtime Subscribe() Breaks on Live?

Question:
wixRealtime.Subscribe() works on Preview mode within the Studio Editor, but does not work on the live site - even when logged-in as the exact same user. Why does Subscribe() break on my live site?

Product:
Editor X

What are you trying to achieve:
To simplify the problem, I have copied JUST the subscribe() logic to a new test page. I am trying to get it so that:

  • On Page Load → run testFunction
  • testFunction should subscribe to a simple fake channel
  • The user should subscribe successfully. This currently errors on live.
    *Error Message: {ErrorCode: 2, Message: ‘subscribe failed’}

What have you already tried:
I have ripped out just the subscribe logic on a blank page to keep it simple. I have also tried various logic-approaches, async+await, then/catch, etc. No luck.

Additional information:

import wixRealtimeFrontend from 'wix-realtime-frontend';

$w.onReady(function () {
	testSubscribe();

});



export function testSubscribe() {
console.log("attempting to dial into a channel");
const channel = {"name": "someChannel"};

wixRealtimeFrontend.subscribe(channel, (message, channel) => {
  let payload = message.payload;
  if(message.publisher) {
    let publisherId = message.publisher.id;
	console.log("message receieved from channel");
  }
})
.then((id) => {
	console.log("subscription successful");
});
}

Here is a picture:
wixCodeQ

wixErrorCode

I’m hitting this same problem implementing Auth0 for member authentication… Have you found any solution yet?

Have you added permissions-router?

Docs here - Permissions Router Introduction | VELO

2 Likes

Thanks for the reply, Noah! I have not tried that. I read a section on that page that mentioned the permissions were optional and subsequently ignored the rest… :slight_smile:

I’m going to give it a try now!

1 Like

This was the issue. The documentation made me think that the permissions were optional:

If this function is not defined, all subscribers will receive the default permissions, which are: {"read": true}

However, it is important to still have the ‘realtime-permissions.js’ file apparently.

Thank you for your help, you’re a lifesaver. It works great now!