fix: logout error

This commit is contained in:
Chareice 2025-01-01 22:28:50 +08:00
parent 382ff55a1c
commit c1eb366701
No known key found for this signature in database
4 changed files with 19 additions and 1 deletions

View File

@ -157,7 +157,7 @@ export class Application {
private initListeners() {
this.eventBus.addEventListener('auth:tokenChanged', (event: CustomEvent) => {
this.setTokenInWebSocket(event.detail.token);
this.setTokenInWebSocket(event.detail);
});
this.eventBus.addEventListener('maintaining:end', () => {

View File

@ -444,6 +444,10 @@ export class Gateway extends EventEmitter {
this.wsServer.setClientTag(clientId, tagKey, tagValue);
});
app.on('ws:removeTag', ({ clientId, tagKey }) => {
this.wsServer.removeClientTag(clientId, tagKey);
});
app.on('ws:sendToTag', ({ tagKey, tagValue, message }) => {
this.wsServer.sendToConnectionsByTags(
[

View File

@ -159,6 +159,16 @@ export class WSServer extends EventEmitter {
console.log(`client tags: ${Array.from(client.tags)}`);
}
removeClientTag(clientId: string, tagKey: string) {
const client = this.webSocketClients.get(clientId);
// remove all tags with the given tagKey
client.tags.forEach((tag) => {
if (tag.startsWith(tagKey)) {
client.tags.delete(tag);
}
});
}
async setClientApp(client: WebSocketClient) {
const req: IncomingRequest = {
url: client.url,

View File

@ -125,6 +125,10 @@ export class PluginAuthServer extends Plugin {
if (!user) {
this.app.logger.error(`Invalid token: ${payload.token}`);
this.app.emit(`ws:removeTag`, {
clientId,
tagKey: 'userId',
});
return;
}