Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core:realtime:user:unsubscribe:after doesn't report kuid #2524

Closed
ScreamZ opened this issue Feb 17, 2024 · 1 comment
Closed

core:realtime:user:unsubscribe:after doesn't report kuid #2524

ScreamZ opened this issue Feb 17, 2024 · 1 comment
Labels

Comments

@ScreamZ
Copy link

ScreamZ commented Feb 17, 2024

Hello,

Trying to use core:realtime:user:unsubscribe:after to generate a side effect. I do need to access subscription.kuid field, but when I refresh my browser page I don't have access to kuid which is null. Whereas I'm supposed to have the kuid.

Related code :

Create (This is OK, kuid is present)

const subscription = new Subscription(
index,
collection,
request.input.body,
normalized.id,
request.context.connection.id,
request.context.user,
);

This is not OK (kuid missing in unsubscribe)

await this.module.notifier.notifyUser(roomId, request, "out", {
count: room.size,
});
const kuid = global.kuzzle.tokenManager.getKuidFromConnection(connectionId);
const subscription = new Subscription(
room.index,
room.collection,
undefined,
roomId,
connectionId,
{ _id: kuid },
);
global.kuzzle.emit("core:realtime:user:unsubscribe:after", {
/* @deprecated */
requestContext,
/* @deprecated */
room: {
collection: room.collection,
id: roomId,
index: room.index,
},
subscription,
});
}

kuzzle-application-server:dev:   subscription: Subscription {
kuzzle-application-server:dev:     connectionId: '1b07674b-579e-4156-af1b-7b962e35cae5',
kuzzle-application-server:dev:     roomId: 'some_id',
kuzzle-application-server:dev:     index: 'main',
kuzzle-application-server:dev:     collection: 'presence',
kuzzle-application-server:dev:     filters: undefined,
kuzzle-application-server:dev:     kuid: null
kuzzle-application-server:dev:   }
@ScreamZ ScreamZ added the bug label Feb 17, 2024
@rolljee
Copy link
Contributor

rolljee commented Feb 27, 2024

Hello @ScreamZ

From what I see, if you get the kuid to null instead of the value you need it is because Kuzzle has not been able to getKuidFromConnection. Maybe your sdk in your application isn't properly connected with the user upon refresh ? maybe your are calling the unsubscribe method to soon upon refresh ?

Are you able to make a small reproduction of the issue so we can work with that and check if it's really a bug ?

// backend side
    global.kuzzle.on("core:realtime:user:subscribe:after", (data) => {
      console.log("User subscribed to room", data);
    });

    global.kuzzle.on("core:realtime:user:unsubscribe:after", (data) => {
      console.log("User unsubscribed from room", data);
    });


// Front side of an application
      const roomId = await this.$kuzzle.realtime.subscribe(
      "toto",
      "tata",
      {},
      (notification) => {
        console.log("Received notification", notification);
      }
    );
    console.log("Room ID", roomId);

    await this.$kuzzle.realtime.unsubscribe(roomId);

I properly get the kuid in the response object of the event core:realtime:user:unsubscribe:after like so

kuzzle         | User unsubscribed from room {
kuzzle         |   requestContext: RequestContext {
kuzzle         |     'token': null,
kuzzle         |     'user': null,
kuzzle         |     'connection': Connection {
kuzzle         |       'id': 'a98ea515-5885-44ef-936b-904803031f3a',
kuzzle         |       'protocol': null,
kuzzle         |       'ips': [],
kuzzle         |       'misc': {}
kuzzle         |     }
kuzzle         |   },
kuzzle         |   room: {
kuzzle         |     collection: 'tata',
kuzzle         |     id: 'e04221d9d78f8f8cc1594f217ad9c9f71a9e16952a237f24b19df9ec65ba12cf',
kuzzle         |     index: 'toto'
kuzzle         |   },
kuzzle         |   subscription: Subscription {
kuzzle         |     connectionId: 'a98ea515-5885-44ef-936b-904803031f3a',
kuzzle         |     roomId: 'e04221d9d78f8f8cc1594f217ad9c9f71a9e16952a237f24b19df9ec65ba12cf',
kuzzle         |     index: 'toto',
kuzzle         |     collection: 'tata',
kuzzle         |     filters: undefined,
kuzzle         |     kuid: 'admin'
kuzzle         |   }
kuzzle         | }

@rolljee rolljee closed this as completed May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants