mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 14:39:25 +08:00
fix: logout error
This commit is contained in:
parent
382ff55a1c
commit
c1eb366701
@ -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', () => {
|
||||
|
@ -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(
|
||||
[
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user