mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 18:29:15 +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>;
|
type LogoutResultDataType = Record<string, never>;
|
||||||
|
|
||||||
const useLogout = () => {
|
const useLogout = () => {
|
||||||
const { authStore } = useRootStore();
|
const {
|
||||||
|
authStore,
|
||||||
|
userStore: { me },
|
||||||
|
} = useRootStore();
|
||||||
const { socket } = useContext(SocketContext);
|
const { socket } = useContext(SocketContext);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
@ -21,11 +24,24 @@ const useLogout = () => {
|
|||||||
|
|
||||||
const logout = async () => {
|
const logout = async () => {
|
||||||
try {
|
try {
|
||||||
|
const sessionId = window.localStorage.getItem('sessionId');
|
||||||
const result = await authStore.logout();
|
const result = await authStore.logout();
|
||||||
|
|
||||||
history.push('/auth');
|
history.push('/auth');
|
||||||
toast({ title: 'You are logged out.', isClosable: true, status: 'info' });
|
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;
|
return result.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error);
|
handleError(error);
|
||||||
|
|||||||
@ -47,7 +47,7 @@ const MainPage: React.FC<IPageProps> = () => {
|
|||||||
if (stat) {
|
if (stat) {
|
||||||
setOnline(stat.online);
|
setOnline(stat.online);
|
||||||
}
|
}
|
||||||
}, [stat?.online]);
|
}, [stat]);
|
||||||
|
|
||||||
if (me === null || courses === null || stat === null) return <LoadingPage />;
|
if (me === null || courses === null || stat === null) return <LoadingPage />;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user