fix(router): endless recursion in HMR, server selection not available (#2478)
Some checks are pending
Push & Release 🌍 / Automation 🎛️ (push) Waiting to run
Push & Release 🌍 / ${{ github.event_name == 'push' && 'Unstable 🚀⚠️' || 'Stable 🏷️✅' }} (push) Waiting to run
Push & Release 🌍 / GitHub CodeQL 🔬 (push) Waiting to run
Push & Release 🌍 / Deploy 🚀 (push) Blocked by required conditions

This commit is contained in:
Fernando Fernández 2024-10-24 18:44:57 +02:00 committed by GitHub
parent 91324c5164
commit f15bcdeb07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 23 deletions

View File

@ -1,4 +1,4 @@
import { watchSyncEffect } from 'vue'; import { watch } from 'vue';
import { import {
createRouter, createRouter,
createWebHashHistory, createWebHashHistory,
@ -54,19 +54,21 @@ router.back = () => {
leave: route.value.meta.layout.transition.leave ?? backTransition leave: route.value.meta.layout.transition.leave ?? backTransition
}; };
const historyState = router.options.history.state; if (isStr(router.options.history.state.back)) {
if (historyState && isStr(historyState.back)) {
router.go(-1); router.go(-1);
} else { } else {
router.replace('/'); void router.replace('/');
} }
}; };
/** /**
* Re-run the middleware pipeline when the user logs out or state is cleared * 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) { 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 * We run the redirect to /server/add as it's the first page in the login flow
@ -91,5 +93,4 @@ watchSyncEffect(() => {
) { ) {
void router.replace('/server/select'); void router.replace('/server/select');
} }
} }, { flush: 'sync' });
);

View File

@ -36,25 +36,21 @@ export async function loginGuard(
} }
if ( if (
( !isNil(remote.auth.currentServer)
!jsonConfig.allowServerSelection && !isNil(remote.auth.currentUser)
&& serverRoutes.has(to.path) && !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); return doRedir({ path: '/', replace: true }, to);
} }
if (!remote.auth.servers.length) { if (jsonConfig.allowServerSelection) {
return doRedir({ path: serverAddUrl, replace: true }, to); if (!remote.auth.servers.length) {
} else if (isNil(remote.auth.currentServer)) { return doRedir({ path: serverAddUrl, replace: true }, to);
return doRedir({ path: serverSelectUrl, replace: true }, to); } else if (isNil(remote.auth.currentServer)) {
} else if (isNil(remote.auth.currentUser)) { return doRedir({ path: serverSelectUrl, replace: true }, to);
}
} else {
return doRedir({ path: serverLoginUrl, replace: true }, to); return doRedir({ path: serverLoginUrl, replace: true }, to);
} }