Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(frontend): add loading state and fix stale cache on profile email update (#19245)
boojack8e26e4523120
diff --git a/frontend/src/AuthContext.vue b/frontend/src/AuthContext.vueindex 1af661673f..b1e0b93eb6 100644--- a/frontend/src/AuthContext.vue+++ b/frontend/src/AuthContext.vue@@ -72,27 +72,29 @@ onUnmounted(() => {}});-// When current user changed, we need to redirect to the workspace root page.+// When current user changed (e.g., another user logged in from different tab),+// redirect to workspace root with notification.+// Skip if this is a self email update (name changes from users/old@email to users/new@email).watch(() => authStore.currentUserName,- (currentUserName, prevCurrentUserName) => {- if (- currentUserName &&- prevCurrentUserName &&- currentUserName !== prevCurrentUserName- ) {- router.push({- name: WORKSPACE_ROOT_MODULE,- // to force route reload- query: { _r: Date.now() },- });- pushNotification({- module: "bytebase",- style: "INFO",- title: t("auth.login-as-another.title"),- description: t("auth.login-as-another.content"),- });+ (curr, prev) => {+ if (!curr || !prev || curr === prev) return;++ if (authStore.isSelfEmailUpdate) {+ authStore.isSelfEmailUpdate = false;+ return;}++ router.push({+ name: WORKSPACE_ROOT_MODULE,+ query: { _r: Date.now() },+ });+ pushNotification({+ module: "bytebase",+ style: "INFO",+ title: t("auth.login-as-another.title"),+ description: t("auth.login-as-another.content"),+ });});diff --git a/frontend/src/store/modules/user.ts b/frontend/src/store/modules/user.tsindex b4c2f4b104..5cfab8992b 100644--- a/frontend/src/store/modules/user.ts+++ b/frontend/src/store/modules/user.ts@@ -164,10 +164,16 @@ export const useUserStore = defineStore("user", () => {if (!originData) {throw new Error(`user with email ${oldEmail} not found`);}+ const oldName = originData.name;const response = await userServiceClientConnect.updateEmail({name: `users/${oldEmail}`,email: newEmail,});+ // Remove old cache entry since the user's name changes with email+ if (oldName !== response.name) {+ userMapByName.value.delete(oldName);+ userRequestCache.delete(oldName);+ }return setUser(response);};diff --git a/frontend/src/store/modules/v1/auth.ts b/frontend/src/store/modules/v1/auth.tsindex 874ff170da..8bd474c2d4 100644--- a/frontend/src/store/modules/v1/auth.ts+++ b/frontend/src/store/modules/v1/auth.ts@@ -35,8 +35,10 @@ export const useAuthStore = defineStore("auth_v1", () => {const authSessionKey = ref<string>(uniqueId());const actuatorStore = useActuatorV1Store();const unauthenticatedOccurred = ref<boolean>(false);- // Format: users/{user}. {user} is a system-generated unique ID.+ // Format: users/{email}. Changes when user email is updated.const currentUserName = ref<string | undefined>(undefined);+ // Flag to suppress "logged in as another user" notification during self email update+ const isSelfEmailUpdate = ref(false);const isLoggedIn = computed(() => {return (@@ -213,17 +215,26 @@ export const useAuthStore = defineStore("auth_v1", () => {}};+ // Update currentUserName after self email change.+ // Sets flag to suppress "logged in as another user" notification.+ const updateCurrentUserNameForEmailChange = (newName: string) => {+ isSelfEmailUpdate.value = true;+ currentUserName.value = newName;+ };+return {currentUserName,isLoggedIn,unauthenticatedOccurred,requireResetPassword,authSessionKey,+ isSelfEmailUpdate,login,signup,logout,fetchCurrentUser,setRequireResetPassword,+ updateCurrentUserNameForEmailChange,};});diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vueindex b9a8fa1524..ff58697ecc 100644--- a/frontend/src/views/ProfileDashboard.vue+++ b/frontend/src/views/ProfileDashboard.vue@@ -21,12 +21,13 @@<div class="mt-6 flex flex-row justify-stretch gap-x-2"><template v-if="allowEdit"><template v-if="state.editing">- <NButton @click.prevent="cancelEdit">+ <NButton quaternary :disabled="state.saving" @click.prevent="cancelEdit">{{ $t("common.cancel") }}</NButton><NButtontype="primary":disabled="!allowSaveEdit"+ :loading="state.saving"@click.prevent="saveEdit">{{ $t("common.save") }}@@ -251,6 +252,7 @@ import {featureToRef,hasFeature,pushNotification,+ useAuthStore,useCurrentUserV1,useSettingV1Store,useUserStore,@@ -271,6 +273,7 @@ interface LocalState {editing: boolean;editingUser?: User;passwordConfirm: string;+ saving: boolean;showFeatureModal: boolean;showDisable2FAConfirmModal: boolean;showRegenerateRecoveryCodesView: boolean;@@ -282,6 +285,7 @@ const props = defineProps<{const { t } = useI18n();const router = useRouter();+const authStore = useAuthStore();const settingV1Store = useSettingV1Store();const currentUser = useCurrentUserV1();const userStore = useUserStore();@@ -290,6 +294,7 @@ const workspaceStore = useWorkspaceV1Store();const state = reactive<LocalState>({editing: false,passwordConfirm: "",+ saving: false,showFeatureModal: false,showDisable2FAConfirmModal: false,showRegenerateRecoveryCodesView: false,@@ -427,12 +432,19 @@ const saveEdit = async () => {updateMaskPaths.push("password");}+ state.saving = true;try {// Update email using dedicated UpdateEmail API if changedif (emailChanged) {const oldEmail = user.value.email;- await userStore.updateEmail(oldEmail, userPatch.email);+ const updatedUser = await userStore.updateEmail(+ oldEmail,+ userPatch.email+ );migrateUserStorage(oldEmail, userPatch.email);+ if (isSelf.value) {+ authStore.updateCurrentUserNameForEmailChange(updatedUser.name);+ }}// Update other fields using UpdateUser API if any changed@@ -447,6 +459,9 @@ const saveEdit = async () => {regenerateTempMfaSecret: false,}));+ }++ if (emailChanged || updateMaskPaths.length > 0) {pushNotification({module: "bytebase",style: "SUCCESS",@@ -460,6 +475,8 @@ const saveEdit = async () => {title: (error as ConnectError).message || "Failed to update user",});return;+ } finally {+ state.saving = false;}state.editingUser = undefined;