mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: resolve chat anonymous user
This commit is contained in:
parent
d2c3ecf2f8
commit
a1ef3b9707
@ -126,7 +126,12 @@ export default abstract class BaseWebChannelHandler<
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const menu = await this.menuService.getTree();
|
const menu = await this.menuService.getTree();
|
||||||
client.emit('settings', { menu, ...settings });
|
const hasProfile = !!client.data.session?.web?.profile;
|
||||||
|
client.emit('settings', {
|
||||||
|
menu,
|
||||||
|
hasProfile,
|
||||||
|
...settings,
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.warn('Unable to retrieve menu ', err);
|
this.logger.warn('Unable to retrieve menu ', err);
|
||||||
client.emit('settings', settings);
|
client.emit('settings', settings);
|
||||||
|
@ -15,6 +15,7 @@ import React, {
|
|||||||
useEffect,
|
useEffect,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
|
import { Packet, PacketType } from "socket.io-parser";
|
||||||
|
|
||||||
import { useSubscribeBroadcastChannel } from "../hooks/useSubscribeBroadcastChannel";
|
import { useSubscribeBroadcastChannel } from "../hooks/useSubscribeBroadcastChannel";
|
||||||
import { StdEventType } from "../types/chat-io-messages.types";
|
import { StdEventType } from "../types/chat-io-messages.types";
|
||||||
@ -415,13 +416,24 @@ const ChatProvider: React.FC<{
|
|||||||
const endConnection = () => {
|
const endConnection = () => {
|
||||||
setConnectionState(0);
|
setConnectionState(0);
|
||||||
};
|
};
|
||||||
|
const resetProfile = ({ type, data }: Packet) => {
|
||||||
|
if (
|
||||||
|
type === PacketType.EVENT &&
|
||||||
|
data[0] === "settings" &&
|
||||||
|
!data[1]?.hasProfile
|
||||||
|
) {
|
||||||
|
localStorage.removeItem("profile");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
socketCtx.socket.io.on("packet", resetProfile);
|
||||||
socketCtx.socket.io.on("reconnect", reSubscribe);
|
socketCtx.socket.io.on("reconnect", reSubscribe);
|
||||||
socketCtx.socket.io.on("close", endConnection);
|
socketCtx.socket.io.on("close", endConnection);
|
||||||
socketCtx.socket.io.on("reconnect_error", endConnection);
|
socketCtx.socket.io.on("reconnect_error", endConnection);
|
||||||
socketCtx.socket.io.on("reconnect_failed", endConnection);
|
socketCtx.socket.io.on("reconnect_failed", endConnection);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
socketCtx.socket.io.off("packet", resetProfile);
|
||||||
socketCtx.socket.io.off("reconnect", reSubscribe);
|
socketCtx.socket.io.off("reconnect", reSubscribe);
|
||||||
socketCtx.socket.io.off("close", endConnection);
|
socketCtx.socket.io.off("close", endConnection);
|
||||||
socketCtx.socket.io.off("reconnect_error", endConnection);
|
socketCtx.socket.io.off("reconnect_error", endConnection);
|
||||||
|
Loading…
Reference in New Issue
Block a user