Skip to content

Commit

Permalink
fix(router): endless recursion in HMR, server selection not available (
Browse files Browse the repository at this point in the history
  • Loading branch information
ferferga authored Oct 24, 2024
1 parent 91324c5 commit f15bcde
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
17 changes: 9 additions & 8 deletions frontend/src/plugins/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { watchSyncEffect } from 'vue';
import { watch } from 'vue';
import {
createRouter,
createWebHashHistory,
Expand Down Expand Up @@ -54,19 +54,21 @@ router.back = () => {
leave: route.value.meta.layout.transition.leave ?? backTransition
};

const historyState = router.options.history.state;

if (historyState && isStr(historyState.back)) {
if (isStr(router.options.history.state.back)) {
router.go(-1);
} else {
router.replace('/');
void router.replace('/');
}
};

/**
* Re-run the middleware pipeline when the user logs out or state is cleared
*/
watchSyncEffect(() => {
watch([
() => remote.auth.currentUser,
() => remote.auth.servers,
() => remote.auth.currentServer
], () => {
if (!remote.auth.currentUser && remote.auth.servers.length <= 0) {
/**
* We run the redirect to /server/add as it's the first page in the login flow
Expand All @@ -91,5 +93,4 @@ watchSyncEffect(() => {
) {
void router.replace('/server/select');
}
}
);
}, { flush: 'sync' });
26 changes: 11 additions & 15 deletions frontend/src/plugins/router/middlewares/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,21 @@ export async function loginGuard(
}

if (
(
!jsonConfig.allowServerSelection
&& serverRoutes.has(to.path)
)
|| (
!isNil(remote.auth.currentServer)
&& !isNil(remote.auth.currentUser)
&& !isNil(remote.auth.currentUserToken)
&& routes.has(to.path)
)
!isNil(remote.auth.currentServer)
&& !isNil(remote.auth.currentUser)
&& !isNil(remote.auth.currentUserToken)
&& routes.has(to.path)
) {
return doRedir({ path: '/', replace: true }, to);
}

if (!remote.auth.servers.length) {
return doRedir({ path: serverAddUrl, replace: true }, to);
} else if (isNil(remote.auth.currentServer)) {
return doRedir({ path: serverSelectUrl, replace: true }, to);
} else if (isNil(remote.auth.currentUser)) {
if (jsonConfig.allowServerSelection) {
if (!remote.auth.servers.length) {
return doRedir({ path: serverAddUrl, replace: true }, to);
} else if (isNil(remote.auth.currentServer)) {
return doRedir({ path: serverSelectUrl, replace: true }, to);
}
} else {
return doRedir({ path: serverLoginUrl, replace: true }, to);
}

Expand Down

0 comments on commit f15bcde

Please sign in to comment.