Skip to content

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

Add isDevOrDemo util and use it to guard debug menu item to switch account

Tianzhou Chen30bdd62826c6
diff --git a/frontend/src/components/ProfileDropdown.vue b/frontend/src/components/ProfileDropdown.vue
index cdee8f7a47..f35658a8f7 100644
--- a/frontend/src/components/ProfileDropdown.vue
+++ b/frontend/src/components/ProfileDropdown.vue
@@ -9,14 +9,39 @@
aria-label="User menu"
aria-haspopup="true"
>
- <BBAvatar :username="currentUser.attributes.name">
- <img class="rounded-full" src="../assets/avatar.jpeg" alt="" />
- </BBAvatar>
+ <BBAvatar :username="currentUser.attributes.name"> </BBAvatar>
</button>
<BBContextMenu
ref="menu"
class="z-10 origin-top-left absolute right-0 mt-2 w-32 rounded-md shadow-lg"
>
+ <div v-if="isDevOrDemo">
+ <div
+ v-if="currentUser.attributes.email != '[email protected]'"
+ class="py-1"
+ >
+ <div
+ @click.prevent="switchToDBA"
+ class="block px-4 py-2 text-sm leading-5 text-gray-700 hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900"
+ role="menuitem"
+ >
+ Switch to DBA
+ </div>
+ </div>
+ <div
+ v-if="currentUser.attributes.email != '[email protected]'"
+ class="py-1"
+ >
+ <div
+ @click.prevent="switchToDeveloper"
+ class="block px-4 py-2 text-sm leading-5 text-gray-700 hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900"
+ role="menuitem"
+ >
+ Switch to Dev
+ </div>
+ </div>
+ <div class="border-t border-gray-100"></div>
+ </div>
<div class="py-1">
<router-link
to="/setting"
@@ -81,9 +106,41 @@ export default {
});
};
+ const switchToDBA = () => {
+ store
+ .dispatch("auth/login", {
+ type: "loginInfo",
+ attributes: {
+ username: "[email protected]",
+ password: "aaa",
+ },
+ })
+ .then(() => {
+ // Do a full page reload to avoid stale UI state.
+ location.replace("/");
+ });
+ };
+
+ const switchToDeveloper = () => {
+ store
+ .dispatch("auth/login", {
+ type: "loginInfo",
+ attributes: {
+ username: "[email protected]",
+ password: "aaa",
+ },
+ })
+ .then(() => {
+ // Do a full page reload to avoid stale UI state.
+ location.replace("/");
+ });
+ };
+
return {
currentUser,
logout,
+ switchToDBA,
+ switchToDeveloper,
};
},
};
diff --git a/frontend/src/importMeta.d.ts b/frontend/src/importMeta.d.ts
new file mode 100644
index 0000000000..dd9b9f3dbd
--- /dev/null
+++ b/frontend/src/importMeta.d.ts
@@ -0,0 +1,34 @@
+// Copy from https://github.com/vitejs/vite/blob/main/packages/vite/types/importMeta.d.ts
+interface ImportMeta {
+ url: string;
+
+ readonly hot?: {
+ readonly data: any;
+
+ accept(): void;
+ accept(cb: (mod: any) => void): void;
+ accept(dep: string, cb: (mod: any) => void): void;
+ accept(deps: readonly string[], cb: (mods: any[]) => void): void;
+
+ /**
+ * @deprecated
+ */
+ acceptDeps(): never;
+
+ dispose(cb: (data: any) => void): void;
+ decline(): void;
+ invalidate(): void;
+
+ on(event: string, cb: (...args: any[]) => void): void;
+ };
+
+ readonly env: ImportMetaEnv;
+}
+
+interface ImportMetaEnv {
+ [key: string]: string | boolean | undefined;
+ BASE_URL: string;
+ MODE: string;
+ DEV: boolean;
+ PROD: boolean;
+}
diff --git a/frontend/src/main.js b/frontend/src/main.js
index a0bbdd94df..6eed43f128 100644
--- a/frontend/src/main.js
+++ b/frontend/src/main.js
@@ -19,8 +19,9 @@ import {
BBTableCell,
BBTableTabFilter,
} from "./bbkit";
+import { isDevOrDemo } from "./utils";
-if (process.env.NODE_ENV === "development" || import.meta.env.MODE === "demo") {
+if (isDevOrDemo()) {
makeServer();
}
@@ -32,6 +33,8 @@ app.config.globalProperties.window = window;
app.config.globalProperties.console = console;
// Allow template to access moment object
app.config.globalProperties.moment = moment;
+// Allow template to access isDevOrDemo
+app.config.globalProperties.isDevOrDemo = isDevOrDemo();
app
.use(store)
diff --git a/frontend/src/miragejs/fixtures/userList.json b/frontend/src/miragejs/fixtures/userList.json
index e7b79372c2..38bab147e0 100644
--- a/frontend/src/miragejs/fixtures/userList.json
+++ b/frontend/src/miragejs/fixtures/userList.json
@@ -19,8 +19,8 @@
},
{
"id": "4",
- "name": "Mary (DBA)",
- "email": "[email protected]",
+ "name": "Jerry (DBA)",
+ "email": "[email protected]",
"passwordHash": "aaa"
},
{
diff --git a/frontend/src/utils/env.ts b/frontend/src/utils/env.ts
new file mode 100644
index 0000000000..4bae3afa04
--- /dev/null
+++ b/frontend/src/utils/env.ts
@@ -0,0 +1,11 @@
+export function isDev() {
+ return process.env.NODE_ENV === "development";
+}
+
+export function isDemo() {
+ return import.meta.env.MODE === "demo";
+}
+
+export function isDevOrDemo() {
+ return isDev() || isDemo();
+}
diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts
index 9eaf3f9fc3..f78cf25193 100644
--- a/frontend/src/utils/index.ts
+++ b/frontend/src/utils/index.ts
@@ -1,2 +1,3 @@
-export * from "./util";
+export * from "./env";
export * from "./slug";
+export * from "./util";