A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
fix(router-guard): fix some router guard logic
haitao(lj)d72425b34304
diff --git a/ui/src/router/guarder.ts b/ui/src/router/guarder.tsindex 8c5bf7c2..e3b81598 100644--- a/ui/src/router/guarder.ts+++ b/ui/src/router/guarder.ts@@ -7,17 +7,12 @@ import {isLoggedAndInactive,isLoggedAndSuspended,isNotLoggedOrInactive,+ isNotLoggedOrNotSuspend,} from '@/utils/guards';const RouteGuarder = {base: async () => {- return isNotLoggedOrNormal();- },- notLogged: async () => {- return isNotLogged();- },- notLoggedOrInactive: async () => {- return isNotLoggedOrInactive();+ return isNotLoggedOrNotSuspend();},loggedAndNormal: async () => {await pullLoggedUser(true);@@ -33,6 +28,15 @@ const RouteGuarder = {await pullLoggedUser(true);return isAdminLogged();},+ notLogged: async () => {+ return isNotLogged();+ },+ notLoggedOrNormal: async () => {+ return isNotLoggedOrNormal();+ },+ notLoggedOrInactive: async () => {+ return isNotLoggedOrInactive();+ },};export default RouteGuarder;diff --git a/ui/src/utils/guards.ts b/ui/src/utils/guards.tsindex f0faf55b..47f79605 100644--- a/ui/src/utils/guards.ts+++ b/ui/src/utils/guards.ts@@ -94,21 +94,21 @@ export const isNotLogged = () => {};export const isLoggedAndInactive = () => {- const ret: GuardResult = { ok: false, redirect: undefined };+ const ret: GuardResult = { ok: true, redirect: undefined };const userStat = deriveUserStat();- if (!userStat.isActivated) {- ret.ok = true;- ret.redirect = RouteAlias.activation;+ if (userStat.isActivated) {+ ret.ok = false;+ ret.redirect = RouteAlias.home;}return ret;};export const isLoggedAndSuspended = () => {- const ret: GuardResult = { ok: false, redirect: undefined };+ const ret: GuardResult = { ok: true, redirect: undefined };const userStat = deriveUserStat();- if (userStat.isSuspended) {- ret.redirect = RouteAlias.suspended;- ret.ok = true;+ if (!userStat.isSuspended) {+ ret.ok = false;+ ret.redirect = RouteAlias.home;}return ret;};@@ -120,7 +120,7 @@ export const isLoggedAndNormal = () => {ret.ok = true;} else if (!userStat.isActivated) {ret.redirect = RouteAlias.activation;- } else if (!userStat.isSuspended) {+ } else if (userStat.isSuspended) {ret.redirect = RouteAlias.suspended;} else if (!userStat.isLogged) {ret.redirect = RouteAlias.login;@@ -139,12 +139,26 @@ export const isNotLoggedOrNormal = () => {return ret;};+export const isNotLoggedOrNotSuspend = () => {+ const ret: GuardResult = { ok: true, redirect: undefined };+ const userStat = deriveUserStat();+ const gr = isLoggedAndNormal();+ if (!gr.ok && userStat.isSuspended) {+ ret.ok = false;+ ret.redirect = gr.redirect;+ }+ return ret;+};+export const isNotLoggedOrInactive = () => {const ret: GuardResult = { ok: true, redirect: undefined };const userStat = deriveUserStat();- if (userStat.isLogged || userStat.isActivated) {+ if (userStat.isActivated) {ret.ok = false;ret.redirect = RouteAlias.home;+ } else if (userStat.isSuspended) {+ ret.ok = false;+ ret.redirect = RouteAlias.suspended;}return ret;};