feat: Enhance user state management with polling and WebSocket connection handling
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user