mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 10:19:22 +03:00
feat: online status
This commit is contained in:
parent
bfbf0e8064
commit
cdce2c5512
@ -13,7 +13,10 @@ import { SocketContext } from '@educt/contexts';
|
||||
type LogoutResultDataType = Record<string, never>;
|
||||
|
||||
const useLogout = () => {
|
||||
const { authStore } = useRootStore();
|
||||
const {
|
||||
authStore,
|
||||
userStore: { me },
|
||||
} = useRootStore();
|
||||
const { socket } = useContext(SocketContext);
|
||||
const history = useHistory();
|
||||
const toast = useToast();
|
||||
@ -21,11 +24,24 @@ const useLogout = () => {
|
||||
|
||||
const logout = async () => {
|
||||
try {
|
||||
const sessionId = window.localStorage.getItem('sessionId');
|
||||
const result = await authStore.logout();
|
||||
|
||||
history.push('/auth');
|
||||
toast({ title: 'You are logged out.', isClosable: true, status: 'info' });
|
||||
// window.localStorage.removeItem('sessionId');
|
||||
socket?.disconnect();
|
||||
|
||||
/**
|
||||
* Destroy session
|
||||
*/
|
||||
if (sessionId) {
|
||||
if (socket) {
|
||||
socket.auth = { sessionId: undefined };
|
||||
// socket.emit('user:logout', { sessionId });
|
||||
socket.disconnect();
|
||||
}
|
||||
window.localStorage.removeItem('sessionId');
|
||||
}
|
||||
|
||||
return result.data;
|
||||
} catch (error) {
|
||||
handleError(error);
|
||||
|
||||
@ -47,7 +47,7 @@ const MainPage: React.FC<IPageProps> = () => {
|
||||
if (stat) {
|
||||
setOnline(stat.online);
|
||||
}
|
||||
}, [stat?.online]);
|
||||
}, [stat]);
|
||||
|
||||
if (me === null || courses === null || stat === null) return <LoadingPage />;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user