Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Fetch the basic info required by route authentication before mounting the app
天舟9b95358013e0
diff --git a/frontend/src/App.vue b/frontend/src/App.vueindex f2552d1b0b..224d7ac292 100644--- a/frontend/src/App.vue+++ b/frontend/src/App.vue@@ -1,14 +1,5 @@<template>- <Suspense>- <template #default>- <ProvideAppContext>- <router-view />- </ProvideAppContext>- </template>- <template #fallback>- <span class="items-center flex">Loading...</span>- </template>- </Suspense>+ <router-view /><template v-if="state.notificationList.length > 0"><BBNotification:placement="'BOTTOM_RIGHT'"@@ -22,7 +13,6 @@import { reactive, watchEffect, onErrorCaptured } from "vue";import { useStore } from "vuex";import { useRouter } from "vue-router";-import ProvideAppContext from "./components/ProvideAppContext.vue";import { isDev } from "./utils";import { Notification } from "./types";import { BBNotificationItem } from "./bbkit/types";@@ -40,7 +30,7 @@ interface LocalState {export default {name: "App",- components: { ProvideAppContext },+ components: {},setup(props, ctx) {const store = useStore();const router = useRouter();diff --git a/frontend/src/AppError.vue b/frontend/src/AppError.vuenew file mode 100644index 0000000000..9b0a3a9579--- /dev/null+++ b/frontend/src/AppError.vue@@ -0,0 +1,13 @@+<template>+ <h1 class="m-4">+ Connecting server timeout. Make sure the server is running.+ </h1>+</template>++<script lang="ts">+export default {+ name: "AppError",+ components: {},+ setup(props, ctx) {},+};+</script>diff --git a/frontend/src/components/ProfileDropdown.vue b/frontend/src/components/ProfileDropdown.vueindex 4706ca2f18..6c60f92a07 100644--- a/frontend/src/components/ProfileDropdown.vue+++ b/frontend/src/components/ProfileDropdown.vue@@ -176,7 +176,7 @@ export default {};const ping = () => {- store.dispatch("actuator/info").then((info: ServerInfo) => {+ store.dispatch("actuator/fetchInfo").then((info: ServerInfo) => {store.dispatch("notification/pushNotification", {module: "bytebase",style: "SUCCESS",diff --git a/frontend/src/components/ProvideAppContext.vue b/frontend/src/components/ProvideAppContext.vuedeleted file mode 100644index df05ae6c14..0000000000--- a/frontend/src/components/ProvideAppContext.vue+++ /dev/null@@ -1,22 +0,0 @@-<template>- <slot />-</template>--<script lang="ts">-import { useStore } from "vuex";--export default {- name: "ProvideAppContext",- async setup() {- const store = useStore();-- // Restore login user first.- await store.dispatch("auth/restoreUser");-- await Promise.all([- store.dispatch("actuator/info"),- store.dispatch("plan/fetchCurrentPlan"),- ]);- },-};-</script>diff --git a/frontend/src/layouts/DashboardLayout.vue b/frontend/src/layouts/DashboardLayout.vueindex 11e31c5efc..956ecc95e7 100644--- a/frontend/src/layouts/DashboardLayout.vue+++ b/frontend/src/layouts/DashboardLayout.vue@@ -63,7 +63,7 @@ export default {const store = useStore();const ping = () => {- store.dispatch("actuator/info").then((info: ServerInfo) => {+ store.dispatch("actuator/fetchInfo").then((info: ServerInfo) => {store.dispatch("notification/pushNotification", {module: "bytebase",style: "SUCCESS",diff --git a/frontend/src/main.ts b/frontend/src/main.tsindex 5c2c200ba2..8e4492debc 100644--- a/frontend/src/main.ts+++ b/frontend/src/main.ts@@ -2,6 +2,7 @@ import { createApp } from "vue";import axios from "axios";import moment from "moment";import App from "./App.vue";+import AppError from "./AppError.vue";import { store } from "./store";import { router } from "./router";import "./assets/css/inter.css";@@ -49,27 +50,6 @@ import {dataSourceSlug,registerStoreWithRoleUtil,} from "./utils";-import { ServerInfo } from "./types";--const app = createApp(App);--// Allow template to access various function-app.config.globalProperties.window = window;-app.config.globalProperties.console = console;-app.config.globalProperties.moment = moment;-app.config.globalProperties.humanizeTs = humanizeTs;-app.config.globalProperties.isDev = isDev();-app.config.globalProperties.isRelease = isRelease();-app.config.globalProperties.sizeToFit = sizeToFit;-app.config.globalProperties.urlfy = urlfy;-app.config.globalProperties.environmentName = environmentName;-app.config.globalProperties.environmentSlug = environmentSlug;-app.config.globalProperties.projectName = projectName;-app.config.globalProperties.projectSlug = projectSlug;-app.config.globalProperties.instanceName = instanceName;-app.config.globalProperties.instanceSlug = instanceSlug;-app.config.globalProperties.databaseSlug = databaseSlug;-app.config.globalProperties.dataSourceSlug = dataSourceSlug;registerStoreWithRoleUtil(store);@@ -136,34 +116,67 @@ axios.interceptors.response.use(// app.config.errorHandler = function (err, vm, info) {// };-app- // Need to use a directive on the element.- // The normal hljs.initHighlightingOnLoad() won't work because router change would cause vue- // to re-render the page and remove the event listener required for- .directive("highlight", highlight)- .directive("data-source-type", dataSourceType)- .use(store)- .use(router)- .component("BBAlert", BBAlert)- .component("BBAttention", BBAttention)- .component("BBAvatar", BBAvatar)- .component("BBButtonAdd", BBButtonAdd)- .component("BBButtonConfirm", BBButtonConfirm)- .component("BBCheckbox", BBCheckbox)- .component("BBContextMenu", BBContextMenu)- .component("BBModal", BBModal)- .component("BBNotification", BBNotification)- .component("BBOutline", BBOutline)- .component("BBSelect", BBSelect)- .component("BBStepBar", BBStepBar)- .component("BBStepTab", BBStepTab)- .component("BBSwitch", BBSwitch)- .component("BBTab", BBTab)- .component("BBTabPanel", BBTabPanel)- .component("BBTable", BBTable)- .component("BBTableCell", BBTableCell)- .component("BBTableHeaderCell", BBTableHeaderCell)- .component("BBTableSearch", BBTableSearch)- .component("BBTabFilter", BBTabFilter)- .component("BBTextField", BBTextField)- .mount("#app");+// We need to restore the basic info in order to perform route authentication.+// Even using the <suspense>, it's still too late, thus we do the fetch here.+await Promise.all([+ store.dispatch("actuator/fetchInfo"),+ store.dispatch("plan/fetchCurrentPlan"),+ store.dispatch("auth/restoreUser"),+])+ .then(() => {+ const app = createApp(App);++ // Allow template to access various function+ app.config.globalProperties.window = window;+ app.config.globalProperties.console = console;+ app.config.globalProperties.moment = moment;+ app.config.globalProperties.humanizeTs = humanizeTs;+ app.config.globalProperties.isDev = isDev();+ app.config.globalProperties.isRelease = isRelease();+ app.config.globalProperties.sizeToFit = sizeToFit;+ app.config.globalProperties.urlfy = urlfy;+ app.config.globalProperties.environmentName = environmentName;+ app.config.globalProperties.environmentSlug = environmentSlug;+ app.config.globalProperties.projectName = projectName;+ app.config.globalProperties.projectSlug = projectSlug;+ app.config.globalProperties.instanceName = instanceName;+ app.config.globalProperties.instanceSlug = instanceSlug;+ app.config.globalProperties.databaseSlug = databaseSlug;+ app.config.globalProperties.dataSourceSlug = dataSourceSlug;++ app+ // Need to use a directive on the element.+ // The normal hljs.initHighlightingOnLoad() won't work because router change would cause vue+ // to re-render the page and remove the event listener required for+ .directive("highlight", highlight)+ .directive("data-source-type", dataSourceType)+ .use(store)+ .use(router)+ .component("BBAlert", BBAlert)+ .component("BBAttention", BBAttention)+ .component("BBAvatar", BBAvatar)+ .component("BBButtonAdd", BBButtonAdd)+ .component("BBButtonConfirm", BBButtonConfirm)+ .component("BBCheckbox", BBCheckbox)+ .component("BBContextMenu", BBContextMenu)+ .component("BBModal", BBModal)+ .component("BBNotification", BBNotification)+ .component("BBOutline", BBOutline)+ .component("BBSelect", BBSelect)+ .component("BBStepBar", BBStepBar)+ .component("BBStepTab", BBStepTab)+ .component("BBSwitch", BBSwitch)+ .component("BBTab", BBTab)+ .component("BBTabPanel", BBTabPanel)+ .component("BBTable", BBTable)+ .component("BBTableCell", BBTableCell)+ .component("BBTableHeaderCell", BBTableHeaderCell)+ .component("BBTableSearch", BBTableSearch)+ .component("BBTabFilter", BBTabFilter)+ .component("BBTextField", BBTextField)+ .mount("#app");+ })+ .catch(() => {+ const app = createApp(AppError);+ app.mount("#app");+ });diff --git a/frontend/src/store/modules/actuator.ts b/frontend/src/store/modules/actuator.tsindex 35dd3c2afc..c9bc09f6c6 100644--- a/frontend/src/store/modules/actuator.ts+++ b/frontend/src/store/modules/actuator.ts@@ -24,7 +24,7 @@ const getters = {};const actions = {- async info({ commit }: any): Promise<ServerInfo> {+ async fetchInfo({ commit }: any): Promise<ServerInfo> {const serverInfo = (await axios.get(`/api/actuator/info`)).data;commit("setInfo", serverInfo);diff --git a/frontend/src/views/auth/Signin.vue b/frontend/src/views/auth/Signin.vueindex 97a4038f77..1fbada76b9 100644--- a/frontend/src/views/auth/Signin.vue+++ b/frontend/src/views/auth/Signin.vue@@ -123,10 +123,10 @@</template><script lang="ts">-import { computed, reactive, watchEffect } from "vue";+import { computed, onMounted, reactive } from "vue";import { useStore } from "vuex";import { useRouter } from "vue-router";-import { LoginInfo, ServerInfo } from "../../types";+import { LoginInfo } from "../../types";import { isDev, isValidEmail } from "../../utils";interface LocalState {@@ -145,21 +145,17 @@ export default {password: "",});- const prepareInfo = () => {- store.dispatch("actuator/info").then((info: ServerInfo) => {- const demo = store.getters["actuator/isDemo"]();- state.email = isDev() || demo ? "[email protected]" : "";- state.password = isDev() || demo ? "1024" : "";- // Navigate to signup if needs admin setup.- // Unable to achieve it in router.beforeEach because actutor/info is fetched async and returns- // after router has already made the decision on first page load.- if (info.needAdminSetup) {- router.push({ name: "auth.signup", replace: true });- }- });- };-- watchEffect(prepareInfo);+ onMounted(() => {+ const demo = store.getters["actuator/isDemo"]();+ state.email = isDev() || demo ? "[email protected]" : "";+ state.password = isDev() || demo ? "1024" : "";+ // Navigate to signup if needs admin setup.+ // Unable to achieve it in router.beforeEach because actutor/info is fetched async and returns+ // after router has already made the decision on first page load.+ if (store.getters["actuator/needAdminSetup"]()) {+ router.push({ name: "auth.signup", replace: true });+ }+ });const allowSignin = computed(() => {return isValidEmail(state.email) && state.password;