mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-08 06:59:26 +08:00
fix: logout error
This commit is contained in:
parent
382ff55a1c
commit
c1eb366701
@ -157,7 +157,7 @@ export class Application {
|
|||||||
|
|
||||||
private initListeners() {
|
private initListeners() {
|
||||||
this.eventBus.addEventListener('auth:tokenChanged', (event: CustomEvent) => {
|
this.eventBus.addEventListener('auth:tokenChanged', (event: CustomEvent) => {
|
||||||
this.setTokenInWebSocket(event.detail.token);
|
this.setTokenInWebSocket(event.detail);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.eventBus.addEventListener('maintaining:end', () => {
|
this.eventBus.addEventListener('maintaining:end', () => {
|
||||||
|
@ -444,6 +444,10 @@ export class Gateway extends EventEmitter {
|
|||||||
this.wsServer.setClientTag(clientId, tagKey, tagValue);
|
this.wsServer.setClientTag(clientId, tagKey, tagValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.on('ws:removeTag', ({ clientId, tagKey }) => {
|
||||||
|
this.wsServer.removeClientTag(clientId, tagKey);
|
||||||
|
});
|
||||||
|
|
||||||
app.on('ws:sendToTag', ({ tagKey, tagValue, message }) => {
|
app.on('ws:sendToTag', ({ tagKey, tagValue, message }) => {
|
||||||
this.wsServer.sendToConnectionsByTags(
|
this.wsServer.sendToConnectionsByTags(
|
||||||
[
|
[
|
||||||
|
@ -159,6 +159,16 @@ export class WSServer extends EventEmitter {
|
|||||||
console.log(`client tags: ${Array.from(client.tags)}`);
|
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) {
|
async setClientApp(client: WebSocketClient) {
|
||||||
const req: IncomingRequest = {
|
const req: IncomingRequest = {
|
||||||
url: client.url,
|
url: client.url,
|
||||||
|
@ -125,6 +125,10 @@ export class PluginAuthServer extends Plugin {
|
|||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
this.app.logger.error(`Invalid token: ${payload.token}`);
|
this.app.logger.error(`Invalid token: ${payload.token}`);
|
||||||
|
this.app.emit(`ws:removeTag`, {
|
||||||
|
clientId,
|
||||||
|
tagKey: 'userId',
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user