feat: Enhance user state management with polling and WebSocket connection handling

This commit is contained in:
2026-01-07 21:42:21 +01:00
parent ef073afd5e
commit 02869fff8b
8 changed files with 163 additions and 25 deletions

View File

@@ -73,8 +73,12 @@ router.beforeEach(async (to, from, next) => {
if (isOnline) {
try {
const response = await axios.get(`${api}/userInfo`, { withCredentials: true });
info.setUserInfo(response.data.username, response.data.userId);
await info.requestState();
if (!info.username) {
info.clearUserInfo();
return next('/login');
}
return next({ name: 'mainmenu' });
@@ -92,11 +96,17 @@ router.beforeEach(async (to, from, next) => {
if (!to.meta.requiresAuth) return next();
try {
await axios.get(`${api}/userInfo`, { withCredentials: true }).then(
res => {
info.setUserInfo(res.data.username, res.data.userId);
}
);
await info.requestState();
if (!info.username) {
info.clearUserInfo();
return next('/login');
}
if (info.gameId && to.name !== 'game') {
return next({ name: 'game' });
}
next();
} catch (err) {
info.clearUserInfo();