Skip to content

Commit

Permalink
refactor: simplify loginGuard logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ferferga committed Aug 9, 2024
1 parent d6e0d42 commit 44e533e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions frontend/src/plugins/router/middlewares/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ export async function loginGuard(
let destinationRoute: RouteLocationPathRaw | undefined;
const jsonConfig = await getJSONConfig();

if (!jsonConfig.allowServerSelection && (to.path === serverAddUrl || to.path === serverSelectUrl)) {
return false;
}

if (!isNil(remote.auth.currentServer) && !isNil(remote.auth.currentUser) && !isNil(remote.auth.currentUserToken) && routes.has(to.path)) {
destinationRoute = { path: '/', replace: true };
} else if (to.path === serverAddUrl && remote.auth.servers.length > 0 || to.path === serverSelectUrl) {
if (!jsonConfig.allowServerSelection) {
destinationRoute = { path: serverLoginUrl, replace: true };
}
}

if (remote.auth.servers.length <= 0 && jsonConfig.defaultServerURLs.length <= 0) {
destinationRoute = { path: serverAddUrl, replace: true };
} else if (!routes.has(to.path)) {
if (isNil(remote.auth.currentServer)) {
if (jsonConfig.allowServerSelection) {
destinationRoute = { path: serverSelectUrl, replace: true };
} else {
if (jsonConfig.defaultServerURLs.length) {
await until(() => remote.auth.currentServer).toBeTruthy({ flush: 'pre' });

return loginGuard(to);
}

destinationRoute = { path: serverSelectUrl, replace: true };
} else if (isNil(remote.auth.currentUser)) {
destinationRoute = { path: serverLoginUrl, replace: true };
}
Expand Down

0 comments on commit 44e533e

Please sign in to comment.