Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: split auth routes (#10247)

boojackad3a2571ddc7
diff --git a/frontend/src/layouts/SplashLayout.vue b/frontend/src/layouts/SplashLayout.vue
index 0116d00e8e..6c00d3caa2 100644
--- a/frontend/src/layouts/SplashLayout.vue
+++ b/frontend/src/layouts/SplashLayout.vue
@@ -4,13 +4,13 @@
<img
v-if="route == 'auth.signup'"
class="absolute inset-0 h-full w-full object-cover"
- src="../assets/illustration/signup.webp"
+ src="@/assets/illustration/signup.webp"
alt=""
/>
<img
v-else
class="absolute inset-0 h-full w-full object-cover"
- src="../assets/illustration/signin.webp"
+ src="@/assets/illustration/signin.webp"
alt=""
/>
</div>
@@ -22,22 +22,13 @@
</div>
</template>
-<script lang="ts">
+<script lang="ts" setup>
import { computed } from "vue";
import { useRouter } from "vue-router";
-export default {
- name: "SplashLayout",
- setup() {
- const router = useRouter();
+const router = useRouter();
- const route = computed(() => {
- return router.currentRoute.value.name;
- });
-
- return {
- route,
- };
- },
-};
+const route = computed(() => {
+ return router.currentRoute.value.name;
+});
</script>
diff --git a/frontend/src/router/auth.ts b/frontend/src/router/auth.ts
new file mode 100644
index 0000000000..21ad2677f7
--- /dev/null
+++ b/frontend/src/router/auth.ts
@@ -0,0 +1,64 @@
+import { RouteRecordRaw } from "vue-router";
+import SplashLayout from "@/layouts/SplashLayout.vue";
+import { t } from "@/plugins/i18n";
+
+export const AUTH_SIGNIN_MODULE = "auth.signin";
+export const AUTH_SIGNUP_MODULE = "auth.signup";
+export const AUTH_MFA_MODULE = "auth.mfa";
+export const AUTH_PASSWORD_FORGOT_MODULE = "auth.password.forgot";
+export const AUTH_OAUTH_CALLBACK_MODULE = "auth.oauth.callback";
+export const AUTH_OIDC_CALLBACK_MODULE = "auth.oidc.callback";
+export const AUTH_2FA_SETUP_MODULE = "auth.2fa.setup";
+
+const authRoutes: RouteRecordRaw[] = [
+ {
+ path: "/auth",
+ name: "auth",
+ component: SplashLayout,
+ children: [
+ {
+ path: "",
+ alias: "signin",
+ name: AUTH_SIGNIN_MODULE,
+ meta: { title: () => t("common.sign-in") },
+ component: () => import("@/views/auth/Signin.vue"),
+ },
+ {
+ path: "signup",
+ name: AUTH_SIGNUP_MODULE,
+ meta: { title: () => t("common.sign-up") },
+ component: () => import("@/views/auth/Signup.vue"),
+ },
+ {
+ path: "password-forgot",
+ name: AUTH_PASSWORD_FORGOT_MODULE,
+ meta: { title: () => `${t("auth.password-forgot")}` },
+ component: () => import("@/views/auth/PasswordForgot.vue"),
+ },
+ {
+ path: "mfa",
+ name: AUTH_MFA_MODULE,
+ meta: { title: () => t("multi-factor.self") },
+ component: () => import("@/views/auth/MultiFactor.vue"),
+ },
+ ],
+ },
+ {
+ path: "/oauth/callback",
+ name: AUTH_OAUTH_CALLBACK_MODULE,
+ component: () => import("@/views/OAuthCallback.vue"),
+ },
+ {
+ path: "/oidc/callback",
+ name: AUTH_OIDC_CALLBACK_MODULE,
+ component: () => import("@/views/OAuthCallback.vue"),
+ },
+ {
+ path: "/2fa/setup",
+ name: AUTH_2FA_SETUP_MODULE,
+ meta: { title: () => t("two-factor.self") },
+ component: () => import("@/views/TwoFactorRequired.vue"),
+ },
+];
+
+export default authRoutes;
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 15cc8af42e..872371ac06 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -13,7 +13,6 @@ import DashboardLayout from "@/layouts/DashboardLayout.vue";
import DatabaseLayout from "@/layouts/DatabaseLayout.vue";
import InstanceLayout from "@/layouts/InstanceLayout.vue";
import SQLEditorLayout from "@/layouts/SQLEditorLayout.vue";
-import SplashLayout from "@/layouts/SplashLayout.vue";
import { t } from "@/plugins/i18n";
import {
hasFeature,
@@ -55,91 +54,18 @@ import {
import DashboardSidebar from "@/views/DashboardSidebar.vue";
import Home from "@/views/Home.vue";
import SettingSidebar from "@/views/SettingSidebar.vue";
-import MultiFactor from "@/views/auth/MultiFactor.vue";
-import Signin from "@/views/auth/Signin.vue";
-import Signup from "@/views/auth/Signup.vue";
+import authRoutes, {
+ AUTH_2FA_SETUP_MODULE,
+ AUTH_MFA_MODULE,
+ AUTH_PASSWORD_FORGOT_MODULE,
+ AUTH_SIGNIN_MODULE,
+ AUTH_SIGNUP_MODULE,
+} from "./auth";
const HOME_MODULE = "workspace.home";
-const AUTH_MODULE = "auth";
-const SIGNIN_MODULE = "auth.signin";
-const SIGNUP_MODULE = "auth.signup";
-const MFA_MODULE = "auth.mfa";
-const ACTIVATE_MODULE = "auth.activate";
-const PASSWORD_RESET_MODULE = "auth.password.reset";
-const PASSWORD_FORGOT_MODULE = "auth.password.forgot";
const SQL_EDITOR_HOME_MODULE = "sql-editor.home";
-const routes: Array<RouteRecordRaw> = [
- {
- path: "/auth",
- name: AUTH_MODULE,
- component: SplashLayout,
- children: [
- {
- path: "",
- name: SIGNIN_MODULE,
- meta: { title: () => t("common.sign-in") },
- component: Signin,
- alias: "signin",
- props: true,
- },
- {
- path: "signup",
- name: SIGNUP_MODULE,
- meta: { title: () => t("common.sign-up") },
- component: Signup,
- props: true,
- },
- // TODO(tianzhou): Disable activate page for now, requires implementing invite
- // {
- // path: "activate",
- // name: ACTIVATE_MODULE,
- // meta: { title: () => "Activate" },
- // component: Activate,
- // props: true,
- // },
- // {
- // path: "password-reset",
- // name: PASSWORD_RESET_MODULE,
- // meta: { title: () => "Reset Password" },
- // component: PasswordReset,
- // props: true,
- // },
- {
- path: "password-forgot",
- name: PASSWORD_FORGOT_MODULE,
- meta: { title: () => `${t("auth.password-forgot")}` },
- component: () => import("../views/auth/PasswordForgot.vue"),
- props: true,
- },
- ],
- },
- {
- path: "/auth/mfa",
- name: MFA_MODULE,
- meta: { title: () => t("multi-factor.self") },
- component: MultiFactor,
- props: true,
- },
- {
- path: "/oauth/callback",
- name: "oauth-callback",
- component: () => import("../views/OAuthCallback.vue"),
- },
- {
- path: "/oidc/callback",
- name: "oidc-callback",
- component: () => import("../views/OAuthCallback.vue"),
- },
- {
- path: "/2fa/setup",
- name: "2fa.setup",
- meta: {
- title: () => t("two-factor.self"),
- },
- component: () => import("../views/TwoFactorRequired.vue"),
- props: true,
- },
+const routes: RouteRecordRaw[] = [
{
path: "/",
component: DashboardLayout,
@@ -933,7 +859,7 @@ const routes: Array<RouteRecordRaw> = [
export const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
- routes,
+ routes: [...authRoutes, ...routes],
linkExactActiveClass: "bg-link-hover",
scrollBehavior(to /*, from, savedPosition */) {
if (to.hash) {
@@ -1000,12 +926,10 @@ router.beforeEach((to, from, next) => {
}
if (
- to.name === SIGNIN_MODULE ||
- to.name === SIGNUP_MODULE ||
- to.name === MFA_MODULE ||
- to.name === ACTIVATE_MODULE ||
- to.name === PASSWORD_RESET_MODULE ||
- to.name === PASSWORD_FORGOT_MODULE
+ to.name === AUTH_SIGNIN_MODULE ||
+ to.name === AUTH_SIGNUP_MODULE ||
+ to.name === AUTH_MFA_MODULE ||
+ to.name === AUTH_PASSWORD_FORGOT_MODULE
) {
useTabStore().reset();
import("@/plugins/ai/store").then(({ useConversationStore }) => {
@@ -1018,18 +942,7 @@ router.beforeEach((to, from, next) => {
}
next({ name: HOME_MODULE, replace: true });
} else {
- if (to.name === ACTIVATE_MODULE) {
- const token = to.query.token;
- if (token) {
- // TODO(tianzhou): Needs to validate the activate token
- next();
- } else {
- // Go to signup if token is missing
- next({ name: SIGNUP_MODULE, replace: true });
- }
- } else {
- next();
- }
+ next();
}
return;
} else {
@@ -1040,7 +953,7 @@ router.beforeEach((to, from, next) => {
}
next({
- name: SIGNIN_MODULE,
+ name: AUTH_SIGNIN_MODULE,
query: query,
replace: true,
});
@@ -1050,14 +963,14 @@ router.beforeEach((to, from, next) => {
// If there is a `redirect` in query param and prev page is signin or signup, redirect to the target route
if (
- (from.name === SIGNIN_MODULE || from.name === SIGNUP_MODULE) &&
+ (from.name === AUTH_SIGNIN_MODULE || from.name === AUTH_SIGNUP_MODULE) &&
typeof from.query.redirect === "string"
) {
window.location.href = from.query.redirect;
return;
}
- if (to.name === "2fa.setup") {
+ if (to.name === AUTH_2FA_SETUP_MODULE) {
next();
return;
}
@@ -1070,7 +983,7 @@ router.beforeEach((to, from, next) => {
const user = currentUserV1.value;
if (user && !user.mfaEnabled) {
next({
- name: "2fa.setup",
+ name: AUTH_2FA_SETUP_MODULE,
replace: true,
});
return;
diff --git a/frontend/src/utils/iam/permission.ts b/frontend/src/utils/iam/permission.ts
index 65a773162e..7615b39ec6 100644
--- a/frontend/src/utils/iam/permission.ts
+++ b/frontend/src/utils/iam/permission.ts
@@ -23,6 +23,16 @@ export const hasProjectPermissionV2 = (
permission: ProjectPermission
): boolean => {
const roleStore = useRoleStore();
+ // Check workspace-level permissions first.
+ // For those users who have workspace-level project roles, they should have all project-level permissions.
+ const workspaceLevelPermissions = user.roles
+ .map((role) => roleStore.getRoleByName(role))
+ .flatMap((role) => (role ? role.permissions : []));
+ if (workspaceLevelPermissions.includes(permission)) {
+ return true;
+ }
+
+ // Check project-level permissions.
const projectIAMPolicy = project.iamPolicy;
const roles = [];
for (const binding of projectIAMPolicy.bindings) {
diff --git a/frontend/src/views/TwoFactorSetup.vue b/frontend/src/views/TwoFactorSetup.vue
index 6d44cb961b..82e359946f 100644
--- a/frontend/src/views/TwoFactorSetup.vue
+++ b/frontend/src/views/TwoFactorSetup.vue
@@ -212,6 +212,9 @@ const tryFinishSetup = async () => {
style: "SUCCESS",
title: t("two-factor.messages.2fa-enabled"),
});
+
+ // When user is on the 2fa.setup page, we'd like to redirect to the home page.
+ // Only happens when the workspace level 2fa-setup is enabled.
if (router.currentRoute.value.name === "2fa.setup") {
router.replace({
path: "/",
diff --git a/frontend/src/views/auth/MultiFactor.vue b/frontend/src/views/auth/MultiFactor.vue
index 8cbde76ea3..e65ee62cb3 100644
--- a/frontend/src/views/auth/MultiFactor.vue
+++ b/frontend/src/views/auth/MultiFactor.vue
@@ -5,7 +5,7 @@
<div class="w-80 bg-white p-8 py-6 rounded-lg shadow">
<img
class="h-12 w-auto mx-auto mb-8"
- src="../../assets/logo-full.svg"
+ src="@/assets/logo-full.svg"
alt="Bytebase"
/>
<form