Skip to content

Commit

Permalink
[MS] Fixed switch org bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-7 committed Jan 8, 2025
1 parent ea627f3 commit 514231f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
6 changes: 3 additions & 3 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"axios": "^1.7.4",
"file-type": "^19.6.0",
"luxon": "^3.4.4",
"megashark-lib": "git+https://github.com/Scille/megashark-lib.git#dadbcb5a858d0e7cc78b02fb993b39a23ec3fba5",
"megashark-lib": "git+https://github.com/Scille/megashark-lib.git#3e8d49c48c492f50830311731a54704f65b86397",
"mammoth": "^1.8.0",
"monaco-editor": "^0.52.0",
"pdfjs-dist": "^4.8.69",
Expand Down
21 changes: 18 additions & 3 deletions client/src/router/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,26 @@ export async function switchOrganization(handle: ConnectionHandle | null, backup
if (!handle) {
await navigateTo(Routes.Home, { skipHandle: true, replace: true });
} else {
const backup = routesBackup.find((bk) => bk.handle === handle);
if (!backup) {
const backupIndex = routesBackup.findIndex((bk) => bk.handle === handle);
// Don't have any backup, just navigate to home
if (backupIndex === -1) {
window.electronAPI.log('error', 'Trying to switch to an organization for which we have no backup information');
return;
}
await navigateTo(Routes.Loading, { skipHandle: true, replace: true, query: { loginInfo: Base64.fromObject(backup) } });
const backup = routesBackup[backupIndex];
try {
await navigateTo(Routes.Loading, { skipHandle: true, replace: true, query: { loginInfo: Base64.fromObject(backup) } });
} catch (e: any) {
// We encounter an error, probably the base64 serialization, we remove the backup and log in to the default page
window.electronAPI.log('error', `Error when switching organization, using default logged in page: ${e}`);
routesBackup.splice(backupIndex, 1);
await navigateTo(Routes.Loading, {
replace: true,
skipHandle: true,
query: {
loginInfo: Base64.fromObject({ handle: backup.handle, data: { route: Routes.Workspaces, params: { handle: backup.handle } } }),
},
});
}
}
}
19 changes: 12 additions & 7 deletions client/src/views/layouts/LoadingLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ onMounted(async () => {
async () => {
const query = getCurrentRouteQuery();
if (query.loginInfo) {
const loginInfo = Base64.toObject(query.loginInfo) as RouteBackup;
await navigateTo(loginInfo.data.route, {
params: loginInfo.data.params,
query: loginInfo.data.query,
skipHandle: true,
replace: true,
});
try {
const loginInfo = Base64.toObject(query.loginInfo) as RouteBackup;
await navigateTo(loginInfo.data.route, {
params: loginInfo.data.params,
query: loginInfo.data.query,
skipHandle: true,
replace: true,
});
} catch (e: any) {
window.electronAPI.log('error', `Invalid log in info provided: ${e}`);
await navigateTo(Routes.Home, { skipHandle: true, replace: true });
}
} else {
window.electronAPI.log('error', 'Trying to log in with no log in info provided');
await navigateTo(Routes.Home, { skipHandle: true, replace: true });
Expand Down
1 change: 1 addition & 0 deletions newsfragments/9287.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a rare bug that could occur when switching organizations

0 comments on commit 514231f

Please sign in to comment.