diff --git a/console/src/modules/system/users/Login.vue b/console/src/modules/system/users/Login.vue index 9c04fe200..5e4432882 100644 --- a/console/src/modules/system/users/Login.vue +++ b/console/src/modules/system/users/Login.vue @@ -14,7 +14,9 @@ import { AppName } from "@/constants/app"; import { locales, getBrowserLanguage, i18n } from "@/locales"; import MdiTranslate from "~icons/mdi/translate"; import { useLocalStorage } from "@vueuse/core"; +import { useRoute } from "vue-router"; +const route = useRoute(); const userStore = useUserStore(); const { globalInfo } = useGlobalInfoFetch(); const { t } = useI18n(); @@ -22,11 +24,42 @@ const { t } = useI18n(); const SIGNUP_TYPE = "signup"; onBeforeMount(() => { - if (!userStore.isAnonymous) { - router.push({ name: "Dashboard" }); + if (userStore.isAnonymous) { + return; } + + if (allowRedirect()) { + window.location.href = route.query.redirect_uri as string; + return; + } + + router.push({ name: "Dashboard" }); }); +function allowRedirect() { + const redirect_uri = route.query.redirect_uri as string; + + if (!redirect_uri || redirect_uri === window.location.href) { + return false; + } + + if (redirect_uri.startsWith("/")) { + return true; + } + + if ( + redirect_uri.startsWith("https://") || + redirect_uri.startsWith("http://") + ) { + const url = new URL(redirect_uri); + if (url.origin === window.location.origin) { + return true; + } + } + + return false; +} + function onLoginSucceed() { window.location.reload(); } diff --git a/console/src/router/guards/auth-check.ts b/console/src/router/guards/auth-check.ts index 7d191bd1f..16b485d5f 100644 --- a/console/src/router/guards/auth-check.ts +++ b/console/src/router/guards/auth-check.ts @@ -13,7 +13,12 @@ export function setupAuthCheckGuard(router: Router) { const userStore = useUserStore(); if (userStore.isAnonymous) { - next({ name: "Login" }); + next({ + name: "Login", + query: { + redirect_uri: from.path !== "/" ? window.location.href : undefined, + }, + }); return; } next();