Skip to content

Commit

Permalink
refactor: remove login-related pages from UI project
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Wang <i@ryanc.cc>
  • Loading branch information
ruibaby committed Sep 27, 2024
1 parent 56cb22a commit a6cc04c
Show file tree
Hide file tree
Showing 22 changed files with 10 additions and 1,252 deletions.
2 changes: 0 additions & 2 deletions ui/console-src/layouts/BasicLayout.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts" setup>
import GlobalSearchModal from "@/components/global-search/GlobalSearchModal.vue";
import LoginModal from "@/components/login/LoginModal.vue";
import { RoutesMenu } from "@/components/menu/RoutesMenu";
import { useRouteMenuGenerator } from "@/composables/use-route-menu-generator";
import { rbacAnnotations } from "@/constants/annotations";
Expand Down Expand Up @@ -303,7 +302,6 @@ onMounted(() => {
v-if="globalSearchVisible"
@close="globalSearchVisible = false"
/>
<LoginModal />
</template>
<style lang="scss">
Expand Down
69 changes: 5 additions & 64 deletions ui/console-src/router/guards/auth-check.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,20 @@
import { rbacAnnotations } from "@/constants/annotations";
import { useUserStore } from "@/stores/user";
import type { Router } from "vue-router";

const whiteList = ["Setup", "Login", "Binding", "ResetPassword", "Redirect"];
const whiteList = ["Setup"];

export function setupAuthCheckGuard(router: Router) {
router.beforeEach((to, from, next) => {
router.beforeEach((to, _, next) => {
const userStore = useUserStore();

if (userStore.isAnonymous) {
if (whiteList.includes(to.name as string)) {
next();
return;
}

next({
name: "Login",
query: {
redirect_uri: encodeURIComponent(window.location.href),
},
});
return;
} else {
if (to.name === "Login") {
if (to.query.redirect_uri) {
next({
name: "Redirect",
query: {
redirect_uri: to.query.redirect_uri,
},
});
return;
}

const roleHasRedirectOnLogin = userStore.currentRoles?.find(
(role) =>
role.metadata.annotations?.[rbacAnnotations.REDIRECT_ON_LOGIN]
);

if (roleHasRedirectOnLogin) {
window.location.href =
roleHasRedirectOnLogin.metadata.annotations?.[
rbacAnnotations.REDIRECT_ON_LOGIN
] || "/uc";
return;
}

next({
name: "Dashboard",
});
return;
}

if (to.name && whiteList.includes(to.name as string)) {
next();
return;
}

// Check allow access console
const { currentRoles } = userStore;

const hasDisallowAccessConsoleRole = currentRoles?.some((role) => {
return (
role.metadata.annotations?.[
rbacAnnotations.DISALLOW_ACCESS_CONSOLE
] === "true"
);
});

if (hasDisallowAccessConsoleRole) {
window.location.href = "/uc";
return;
}

next();
window.location.href = `/login?redirect_uri=${encodeURIComponent(
window.location.href
)}`;
return;
}

Expand Down
2 changes: 1 addition & 1 deletion ui/console-src/router/guards/check-states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useUserStore } from "@/stores/user";
import type { Router } from "vue-router";

export function setupCheckStatesGuard(router: Router) {
router.beforeEach(async (to, from, next) => {
router.beforeEach(async (to, _, next) => {
const userStore = useUserStore();
const { globalInfo } = useGlobalInfoStore();
const { userInitialized, dataInitialized } = globalInfo || {};
Expand Down
2 changes: 1 addition & 1 deletion ui/console-src/router/guards/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { hasPermission } from "@/utils/permission";
import type { Router } from "vue-router";

export function setupPermissionGuard(router: Router) {
router.beforeEach((to, from, next) => {
router.beforeEach((to, _, next) => {
const roleStore = useRoleStore();
const { uiPermissions } = roleStore.permissions;
const { meta } = to;
Expand Down
52 changes: 0 additions & 52 deletions ui/console-src/router/routes.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import GatewayLayout from "@/layouts/GatewayLayout.vue";
import Forbidden from "@/views/exceptions/Forbidden.vue";
import NotFound from "@/views/exceptions/NotFound.vue";
import BasicLayout from "@console/layouts/BasicLayout.vue";
import Binding from "@console/views/system/Binding.vue";
import Login from "@console/views/system/Login.vue";
import Redirect from "@console/views/system/Redirect.vue";
import ResetPassword from "@console/views/system/ResetPassword.vue";
import Setup from "@console/views/system/Setup.vue";
import SetupInitialData from "@console/views/system/SetupInitialData.vue";
import type { RouteRecordRaw } from "vue-router";
Expand All @@ -27,34 +22,6 @@ export const routes: Array<RouteRecordRaw> = [
},
],
},
{
path: "/login",
component: GatewayLayout,
children: [
{
path: "",
name: "Login",
component: Login,
meta: {
title: "core.login.title",
},
},
],
},
{
path: "/binding/:provider",
component: GatewayLayout,
children: [
{
path: "",
name: "Binding",
component: Binding,
meta: {
title: "core.binding.title",
},
},
],
},
{
path: "/setup",
component: Setup,
Expand All @@ -71,25 +38,6 @@ export const routes: Array<RouteRecordRaw> = [
title: "core.setup.title",
},
},
{
path: "/redirect",
name: "Redirect",
component: Redirect,
},
{
path: "/reset-password",
component: GatewayLayout,
children: [
{
path: "",
name: "ResetPassword",
component: ResetPassword,
meta: {
title: "core.reset_password.title",
},
},
],
},
];

export default routes;
87 changes: 0 additions & 87 deletions ui/console-src/views/system/Binding.vue

This file was deleted.

85 changes: 0 additions & 85 deletions ui/console-src/views/system/Login.vue

This file was deleted.

Loading

0 comments on commit a6cc04c

Please sign in to comment.