Skip to content

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

refactor: re-implement auth, principal, member store modules with pinia (#1053)

Liu Jif0a4bce71edb
diff --git a/frontend/src/App.vue b/frontend/src/App.vue
index acee890ee4..81f9c0e304 100644
--- a/frontend/src/App.vue
+++ b/frontend/src/App.vue
@@ -24,7 +24,6 @@
<script lang="ts" setup>
import { reactive, watchEffect, onErrorCaptured } from "vue";
-import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { isDev } from "./utils";
@@ -35,7 +34,7 @@ import BBModalStack from "./bbkit/BBModalStack.vue";
import { NConfigProvider, NDialogProvider } from "naive-ui";
import { themeOverrides, dateLang, generalLang } from "../naive-ui.config";
import { t } from "./plugins/i18n";
-import { useNotificationStore } from "./store";
+import { useAuthStore, useNotificationStore } from "./store";
// Show at most 3 notifications to prevent excessive notification when shit hits the fan.
const MAX_NOTIFICATION_DISPLAY_COUNT = 3;
@@ -50,21 +49,21 @@ interface LocalState {
prevLoggedIn: boolean;
}
-const store = useStore();
+const authStore = useAuthStore();
const notificationStore = useNotificationStore();
const router = useRouter();
const state = reactive<LocalState>({
notificationList: [],
- prevLoggedIn: store.getters["auth/isLoggedIn"](),
+ prevLoggedIn: authStore.isLoggedIn(),
});
setInterval(() => {
- const loggedIn = store.getters["auth/isLoggedIn"]();
+ const loggedIn = authStore.isLoggedIn();
if (state.prevLoggedIn != loggedIn) {
state.prevLoggedIn = loggedIn;
if (!loggedIn) {
- store.dispatch("auth/logout").then(() => {
+ authStore.logout().then(() => {
router.push({ name: "auth.signin" });
});
}
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
index 4e13baacec..962e9b6344 100644
--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
@@ -96,7 +96,6 @@ import {
baseDirectoryWebUrl,
Database,
DatabaseId,
- Principal,
Project,
ProjectId,
Repository,
@@ -116,7 +115,7 @@ import CommonTenantView, {
} from "./CommonTenantView.vue";
import { NTabs, NTabPane } from "naive-ui";
import { useEventListener } from "@vueuse/core";
-import { hasFeature, useEnvironmentList } from "@/store";
+import { hasFeature, useCurrentUser, useEnvironmentList } from "@/store";
type LocalState = ProjectStandardState &
ProjectTenantState &
@@ -154,9 +153,7 @@ export default defineComponent({
const store = useStore();
const router = useRouter();
- const currentUser = computed(
- () => store.getters["auth/currentUser"]() as Principal
- );
+ const currentUser = useCurrentUser();
useEventListener(window, "keydown", (e) => {
if (e.code === "Escape") {
diff --git a/frontend/src/components/BookmarkListSidePanel.vue b/frontend/src/components/BookmarkListSidePanel.vue
index 5f9562b918..51d7ad4f1e 100644
--- a/frontend/src/components/BookmarkListSidePanel.vue
+++ b/frontend/src/components/BookmarkListSidePanel.vue
@@ -14,23 +14,21 @@
</template>
<script lang="ts">
-import { computed, watchEffect, defineComponent } from "vue";
-import { useStore } from "vuex";
+import { computed, defineComponent, watchEffect } from "vue";
import { UNKNOWN_ID } from "../types";
import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
-import { useBookmarkStore } from "@/store";
+import { useBookmarkStore, useCurrentUser } from "@/store";
export default defineComponent({
name: "BookmarkListSidePanel",
setup() {
const { t } = useI18n();
- const store = useStore();
const router = useRouter();
const bookmarkStore = useBookmarkStore();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const prepareBookmarkList = () => {
// It will also be called when user logout
diff --git a/frontend/src/components/Breadcrumb.vue b/frontend/src/components/Breadcrumb.vue
index 446e5c436d..2bbf2ef5f1 100644
--- a/frontend/src/components/Breadcrumb.vue
+++ b/frontend/src/components/Breadcrumb.vue
@@ -52,9 +52,14 @@ import { computed, ComputedRef, defineComponent } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
-import { Bookmark, UNKNOWN_ID, Principal, BookmarkCreate } from "../types";
+import { Bookmark, UNKNOWN_ID, BookmarkCreate } from "../types";
import { idFromSlug } from "../utils";
-import { useRouterStore, useUIStateStore, useBookmarkStore } from "@/store";
+import {
+ useCurrentUser,
+ useRouterStore,
+ useUIStateStore,
+ useBookmarkStore,
+} from "@/store";
interface BreadcrumbItem {
name: string;
@@ -71,9 +76,7 @@ export default defineComponent({
const { t } = useI18n();
const bookmarkStore = useBookmarkStore();
- const currentUser: ComputedRef<Principal> = computed(() =>
- store.getters["auth/currentUser"]()
- );
+ const currentUser = useCurrentUser();
const bookmark: ComputedRef<Bookmark> = computed(() =>
bookmarkStore.bookmarkByUserAndLink(
diff --git a/frontend/src/components/CreateDatabasePrepForm.vue b/frontend/src/components/CreateDatabasePrepForm.vue
index a84778cefd..4c547ae88c 100644
--- a/frontend/src/components/CreateDatabasePrepForm.vue
+++ b/frontend/src/components/CreateDatabasePrepForm.vue
@@ -244,7 +244,7 @@ import {
issueSlug,
} from "../utils";
import { useEventListener } from "@vueuse/core";
-import { hasFeature, useEnvironmentStore } from "@/store";
+import { hasFeature, useCurrentUser, useEnvironmentStore } from "@/store";
interface LocalState {
projectId?: ProjectId;
@@ -293,7 +293,7 @@ export default defineComponent({
const store = useStore();
const router = useRouter();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
useEventListener("keydown", (e: KeyboardEvent) => {
if (e.code == "Escape") {
diff --git a/frontend/src/components/DataSourceCreateForm.vue b/frontend/src/components/DataSourceCreateForm.vue
index 02e379a612..36cbd2757c 100644
--- a/frontend/src/components/DataSourceCreateForm.vue
+++ b/frontend/src/components/DataSourceCreateForm.vue
@@ -130,7 +130,7 @@
</template>
<script lang="ts">
-import { computed, PropType, reactive } from "vue";
+import { computed, defineComponent, PropType, reactive } from "vue";
import DatabaseSelect from "./DatabaseSelect.vue";
import { DataSourceCreate, Database, UNKNOWN_ID } from "../types";
import { useI18n } from "vue-i18n";
@@ -140,7 +140,7 @@ interface LocalState {
showPassword: boolean;
}
-export default {
+export default defineComponent({
name: "DataSourceCreateForm",
components: { DatabaseSelect },
props: {
@@ -155,11 +155,6 @@ export default {
},
emits: ["create", "cancel"],
setup(props) {
- // const store = useStore();
-
- // const currentUser: ComputedRef<Principal> = computed(() =>
- // store.getters["auth/currentUser"]()
- // );
const { t } = useI18n();
const state = reactive<LocalState>({
dataSource: {
@@ -185,5 +180,5 @@ export default {
updateDataSource,
};
},
-};
+});
</script>
diff --git a/frontend/src/components/DataSourceMemberTable.vue b/frontend/src/components/DataSourceMemberTable.vue
index e4145220be..105c4a0777 100644
--- a/frontend/src/components/DataSourceMemberTable.vue
+++ b/frontend/src/components/DataSourceMemberTable.vue
@@ -106,13 +106,13 @@
</template>
<script lang="ts">
-import { computed, reactive, PropType, defineComponent } from "vue";
+import { reactive, PropType, defineComponent } from "vue";
import { useStore } from "vuex";
import DataSourceMemberForm from "../components/DataSourceMemberForm.vue";
import PrincipalAvatar from "../components/PrincipalAvatar.vue";
import { DataSource, DataSourceMember } from "../types";
import { useI18n } from "vue-i18n";
-import { pushNotification } from "@/store";
+import { pushNotification, useCurrentUser } from "@/store";
interface LocalState {
searchText: string;
@@ -142,7 +142,7 @@ export default defineComponent({
const { t } = useI18n();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const columnList = [
{
diff --git a/frontend/src/components/DatabaseListSidePanel.vue b/frontend/src/components/DatabaseListSidePanel.vue
index b80cb76586..afbe39eb02 100644
--- a/frontend/src/components/DatabaseListSidePanel.vue
+++ b/frontend/src/components/DatabaseListSidePanel.vue
@@ -22,7 +22,7 @@ import { BBOutlineItem } from "../bbkit/types";
import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
-import { useEnvironmentList, useLabelStore } from "@/store";
+import { useEnvironmentList, useCurrentUser, useLabelStore } from "@/store";
import { storeToRefs } from "pinia";
export default defineComponent({
@@ -33,7 +33,7 @@ export default defineComponent({
const labelStore = useLabelStore();
const router = useRouter();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const rawEnvironmentList = useEnvironmentList();
const environmentList = computed(() =>
diff --git a/frontend/src/components/DatabaseMigrationHistoryPanel.vue b/frontend/src/components/DatabaseMigrationHistoryPanel.vue
index d9fe706acd..f87830f620 100644
--- a/frontend/src/components/DatabaseMigrationHistoryPanel.vue
+++ b/frontend/src/components/DatabaseMigrationHistoryPanel.vue
@@ -89,6 +89,7 @@ import { useRouter } from "vue-router";
import { BBTableSectionDataSource } from "../bbkit/types";
import { instanceSlug, isDBAOrOwner } from "../utils";
import { useI18n } from "vue-i18n";
+import { useCurrentUser } from "@/store";
interface LocalState {
migrationSetupStatus: MigrationSchemaStatus;
@@ -121,7 +122,7 @@ export default defineComponent({
loading: false,
});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const prepareMigrationHistoryList = () => {
state.loading = true;
diff --git a/frontend/src/components/DatabaseOverviewPanel.vue b/frontend/src/components/DatabaseOverviewPanel.vue
index 19e4c01498..8a9b7743bb 100644
--- a/frontend/src/components/DatabaseOverviewPanel.vue
+++ b/frontend/src/components/DatabaseOverviewPanel.vue
@@ -128,7 +128,9 @@
</div>
<div class="relative flex justify-start">
<router-link
- :to="`/db/${databaseSlug}/data-source/${dataSourceSlug(ds)}`"
+ :to="`/db/${databaseSlug}/data-source/${dataSourceSlug(
+ ds
+ )}`"
class="pr-3 bg-white font-medium normal-link"
>{{ ds.name }}</router-link
>
@@ -206,7 +208,7 @@ import { timezoneString, instanceSlug, isDBAOrOwner } from "../utils";
import { Anomaly, Database, DataSource, DataSourcePatch } from "../types";
import { cloneDeep, isEqual } from "lodash-es";
import { BBTableSectionDataSource } from "../bbkit/types";
-import { featureToRef } from "@/store";
+import { featureToRef, useCurrentUser } from "@/store";
interface LocalState {
editingDataSource?: DataSource;
@@ -233,7 +235,7 @@ export default defineComponent({
const state = reactive<LocalState>({});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const prepareTableList = () => {
store.dispatch("table/fetchTableListByDatabaseId", props.database.id);
diff --git a/frontend/src/components/DatabaseSelect.vue b/frontend/src/components/DatabaseSelect.vue
index ebcec8ce4c..39a5e4f729 100644
--- a/frontend/src/components/DatabaseSelect.vue
+++ b/frontend/src/components/DatabaseSelect.vue
@@ -32,12 +32,19 @@
</template>
<script lang="ts">
-import { computed, reactive, watch, watchEffect, PropType } from "vue";
+import { useCurrentUser } from "@/store";
+import {
+ computed,
+ reactive,
+ watch,
+ watchEffect,
+ PropType,
+ defineComponent,
+} from "vue";
import { useStore } from "vuex";
import {
UNKNOWN_ID,
Database,
- Principal,
ProjectId,
InstanceId,
EnvironmentId,
@@ -47,7 +54,7 @@ interface LocalState {
selectedId?: number;
}
-export default {
+export default defineComponent({
name: "DatabaseSelect",
props: {
selectedId: {
@@ -82,9 +89,7 @@ export default {
selectedId: props.selectedId,
});
- const currentUser = computed(
- (): Principal => store.getters["auth/currentUser"]()
- );
+ const currentUser = useCurrentUser();
const prepareDatabaseList = () => {
// TODO(tianzhou): Instead of fetching each time, we maybe able to let the outside context
@@ -172,5 +177,5 @@ export default {
databaseList,
};
},
-};
+});
</script>
diff --git a/frontend/src/components/DatabaseTable.vue b/frontend/src/components/DatabaseTable.vue
index 8453ec1602..28e24ac3ca 100644
--- a/frontend/src/components/DatabaseTable.vue
+++ b/frontend/src/components/DatabaseTable.vue
@@ -248,8 +248,6 @@ const columnListMap = computed(() => {
]);
});
-// const currentUser = computed(() => store.getters["auth/currentUser"]());
-
const showInstanceColumn = computed(() => {
return props.mode != "INSTANCE";
});
diff --git a/frontend/src/components/EnvironmentForm.vue b/frontend/src/components/EnvironmentForm.vue
index 0ee65f7bfa..1b36342dd4 100644
--- a/frontend/src/components/EnvironmentForm.vue
+++ b/frontend/src/components/EnvironmentForm.vue
@@ -202,10 +202,7 @@
<script lang="ts">
import { computed, reactive, PropType, watch, defineComponent } from "vue";
-import { useStore } from "vuex";
-import cloneDeep from "lodash-es/cloneDeep";
-import isEqual from "lodash-es/isEqual";
-import isEmpty from "lodash-es/isEmpty";
+import { cloneDeep, isEqual, isEmpty } from "lodash-es";
import {
Environment,
EnvironmentCreate,
@@ -213,7 +210,7 @@ import {
Policy,
} from "../types";
import { isDBAOrOwner } from "../utils";
-import { useEnvironmentList } from "@/store";
+import { useCurrentUser, useEnvironmentList } from "@/store";
interface LocalState {
environment: Environment | EnvironmentCreate;
@@ -243,7 +240,6 @@ export default defineComponent({
},
emits: ["create", "update", "cancel", "archive", "restore", "update-policy"],
setup(props, { emit }) {
- const store = useStore();
const state = reactive<LocalState>({
environment: cloneDeep(props.environment),
approvalPolicy: cloneDeep(props.approvalPolicy),
@@ -271,7 +267,7 @@ export default defineComponent({
}
);
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const environmentList = useEnvironmentList();
diff --git a/frontend/src/components/InboxList.vue b/frontend/src/components/InboxList.vue
index 4bb66b8fe2..0bdf1d645f 100644
--- a/frontend/src/components/InboxList.vue
+++ b/frontend/src/components/InboxList.vue
@@ -71,6 +71,7 @@ import { isEmpty } from "lodash-es";
import { issueActivityActionSentence } from "../utils";
import { useI18n } from "vue-i18n";
import dayjs from "dayjs";
+import { useCurrentUser } from "@/store";
export default defineComponent({
name: "InboxList",
@@ -86,7 +87,7 @@ export default defineComponent({
const store = useStore();
const router = useRouter();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const actionLink = (activity: Activity): string => {
if (activity.type.startsWith("bb.issue.")) {
diff --git a/frontend/src/components/InstanceForm.vue b/frontend/src/components/InstanceForm.vue
index 7b457680b0..43feacd084 100644
--- a/frontend/src/components/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm.vue
@@ -274,7 +274,7 @@
</template>
<script lang="ts" setup>
-import { computed, reactive, PropType, ComputedRef } from "vue";
+import { computed, reactive, PropType } from "vue";
import { useStore } from "vuex";
import cloneDeep from "lodash-es/cloneDeep";
import isEqual from "lodash-es/isEqual";
@@ -282,7 +282,6 @@ import EnvironmentSelect from "../components/EnvironmentSelect.vue";
import InstanceEngineIcon from "../components/InstanceEngineIcon.vue";
import { isDBAOrOwner } from "../utils";
import {
- Principal,
InstancePatch,
DataSourceType,
Instance,
@@ -293,7 +292,7 @@ import {
} from "../types";
import isEmpty from "lodash-es/isEmpty";
import { useI18n } from "vue-i18n";
-import { pushNotification } from "@/store";
+import { pushNotification, useCurrentUser } from "@/store";
interface EditDataSource extends DataSource {
updatedPassword: string;
@@ -318,9 +317,7 @@ const props = defineProps({
const store = useStore();
const { t } = useI18n();
-const currentUser: ComputedRef<Principal> = computed(() =>
- store.getters["auth/currentUser"]()
-);
+const currentUser = useCurrentUser();
const dataSourceList = props.instance.dataSourceList.map((dataSource) => {
return {
diff --git a/frontend/src/components/Issue/IssueActivityPanel.vue b/frontend/src/components/Issue/IssueActivityPanel.vue
index d5ad7bcac4..738d996800 100644
--- a/frontend/src/components/Issue/IssueActivityPanel.vue
+++ b/frontend/src/components/Issue/IssueActivityPanel.vue
@@ -354,7 +354,11 @@ import {
import { IssueTemplate, IssueBuiltinFieldId } from "../../plugins";
import { useI18n } from "vue-i18n";
import dayjs from "dayjs";
-import { useUIStateStore, useIssueSubscriberStore } from "@/store";
+import {
+ useCurrentUser,
+ useUIStateStore,
+ useIssueSubscriberStore,
+} from "@/store";
interface LocalState {
showDeleteCommentModal: boolean;
@@ -435,7 +439,7 @@ export default defineComponent({
document.removeEventListener("keydown", keyboardHandler);
});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const prepareActivityList = () => {
store.dispatch("activity/fetchActivityListForIssue", props.issue.id);
diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vue
index 03bdcc66b3..0b4c44d2ff 100644
--- a/frontend/src/components/Issue/IssueDetailLayout.vue
+++ b/frontend/src/components/Issue/IssueDetailLayout.vue
@@ -274,7 +274,7 @@ import {
InputField,
OutputField,
} from "../../plugins";
-import { featureToRef, useIssueSubscriberStore } from "@/store";
+import { featureToRef, useCurrentUser, useIssueSubscriberStore } from "@/store";
export default defineComponent({
name: "IssueDetailLayout",
@@ -311,7 +311,7 @@ export default defineComponent({
const route = useRoute();
const issueSubscriberStore = useIssueSubscriberStore();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
watchEffect(function prepare() {
if (props.create) {
diff --git a/frontend/src/components/Issue/IssueOutputPanel.vue b/frontend/src/components/Issue/IssueOutputPanel.vue
index b31cbb1dd7..9df04272ce 100644
--- a/frontend/src/components/Issue/IssueOutputPanel.vue
+++ b/frontend/src/components/Issue/IssueOutputPanel.vue
@@ -98,7 +98,7 @@ import DatabaseSelect from "../DatabaseSelect.vue";
import { activeEnvironment } from "../../utils";
import { OutputField, IssueContext } from "../../plugins";
import { DatabaseId, EnvironmentId, Issue, UNKNOWN_ID } from "../../types";
-import { pushNotification } from "@/store";
+import { pushNotification, useCurrentUser } from "@/store";
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface LocalState {}
@@ -127,7 +127,7 @@ export default defineComponent({
const state = reactive<LocalState>({});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const environmentId = computed((): EnvironmentId => {
return activeEnvironment(props.issue.pipeline).id;
diff --git a/frontend/src/components/Issue/IssueSidebar.vue b/frontend/src/components/Issue/IssueSidebar.vue
index 9732bef7a6..b1b7b9c25d 100644
--- a/frontend/src/components/Issue/IssueSidebar.vue
+++ b/frontend/src/components/Issue/IssueSidebar.vue
@@ -314,7 +314,12 @@ import {
import { useRouter } from "vue-router";
import dayjs from "dayjs";
import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
-import { hasFeature, useEnvironmentStore, useLabelStore } from "@/store";
+import {
+ hasFeature,
+ useCurrentUser,
+ useEnvironmentStore,
+ useLabelStore,
+} from "@/store";
import { storeToRefs } from "pinia";
dayjs.extend(isSameOrAfter);
@@ -403,7 +408,7 @@ export default defineComponent({
}
);
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const fieldValue = (field: InputField): string => {
return props.issue.payload[field.id];
diff --git a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
index fa2947a878..d22901bd5a 100644
--- a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
+++ b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
@@ -139,6 +139,7 @@ import { IssueTemplate } from "../../plugins";
import isEmpty from "lodash-es/isEmpty";
import { useI18n } from "vue-i18n";
import { BBContextMenu } from "../../bbkit";
+import { useCurrentUser } from "@/store";
interface UpdateStatusModalState {
mode: "ISSUE" | "TASK";
@@ -191,7 +192,7 @@ export default defineComponent({
title: "",
});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const issueContext = computed((): IssueContext => {
return {
diff --git a/frontend/src/components/Issue/IssueSubscriberPanel.vue b/frontend/src/components/Issue/IssueSubscriberPanel.vue
index d295395ad1..156fb4c987 100644
--- a/frontend/src/components/Issue/IssueSubscriberPanel.vue
+++ b/frontend/src/components/Issue/IssueSubscriberPanel.vue
@@ -56,8 +56,7 @@ import {
} from "vue";
import PrincipalAvatar from "../PrincipalAvatar.vue";
import { Issue, IssueSubscriber } from "../../types";
-import { useStore } from "vuex";
-import { useIssueSubscriberStore } from "@/store";
+import { useCurrentUser, useIssueSubscriberStore } from "@/store";
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface LocalState {}
@@ -73,11 +72,10 @@ export default defineComponent({
},
emits: ["add-subscriber-id", "remove-subscriber-id"],
setup(props, { emit }) {
- const store = useStore();
const state = reactive<LocalState>({});
const issueSubscriberStore = useIssueSubscriberStore();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const prepareSubscriberList = () => {
issueSubscriberStore.fetchSubscriberListByIssue(props.issue.id);
diff --git a/frontend/src/components/KBar/KBarWrapper.vue b/frontend/src/components/KBar/KBarWrapper.vue
index e7b38bbb60..1f48e85ce4 100644
--- a/frontend/src/components/KBar/KBarWrapper.vue
+++ b/frontend/src/components/KBar/KBarWrapper.vue
@@ -29,13 +29,13 @@ import {
defineAction,
} from "@bytebase/vue-kbar";
import { compareAction as compare } from "./utils";
-import { useStore } from "vuex";
import { useRouter } from "vue-router";
import RenderResults from "./RenderResults.vue";
import KBarHelper from "./KBarHelper.vue";
import KBarFooter from "./KBarFooter.vue";
import { useI18n } from "vue-i18n";
import { useModalStackStatus } from "../../bbkit/BBModalStack.vue";
+import { useAuthStore } from "@/store";
export default defineComponent({
name: "KBarWrapper",
@@ -51,7 +51,6 @@ export default defineComponent({
},
setup() {
const { t } = useI18n();
- const store = useStore();
const router = useRouter();
const modalStack = useModalStackStatus();
@@ -66,7 +65,7 @@ export default defineComponent({
return true;
}
- const currentUser = store.getters["auth/currentUser"]();
+ const currentUser = useAuthStore().currentUser;
// totally disable kbar when not logged in
// since there is no point to show it on signin/signup pages
return !currentUser || currentUser.id < 0;
diff --git a/frontend/src/components/MemberAddOrInvite.vue b/frontend/src/components/MemberAddOrInvite.vue
index c0f99f3083..20e801a645 100644
--- a/frontend/src/components/MemberAddOrInvite.vue
+++ b/frontend/src/components/MemberAddOrInvite.vue
@@ -106,7 +106,6 @@
<script lang="ts">
import { computed, defineComponent, reactive } from "vue";
-import { useStore } from "vuex";
import RoleSelect from "./RoleSelect.vue";
import {
Principal,
@@ -116,7 +115,13 @@ import {
UNKNOWN_ID,
} from "../types";
import { isOwner, isValidEmail } from "../utils";
-import { useUIStateStore, featureToRef } from "@/store";
+import {
+ useUIStateStore,
+ featureToRef,
+ useCurrentUser,
+ usePrincipalStore,
+ useMemberStore,
+} from "@/store";
type User = {
email: string;
@@ -133,9 +138,9 @@ export default defineComponent({
components: { RoleSelect },
props: {},
setup() {
- const store = useStore();
+ const memberStore = useMemberStore();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const isAdd = computed(() => {
return isOwner(currentUser.value.role);
@@ -161,7 +166,7 @@ export default defineComponent({
if (!isValidEmail(user.email)) {
return "Invalid email address";
} else {
- const member = store.getters["member/memberByEmail"](user.email);
+ const member = memberStore.memberByEmail(user.email);
if (member.id != UNKNOWN_ID) {
return "Already a member";
}
@@ -218,8 +223,8 @@ export default defineComponent({
name: user.email.split("@")[0],
email: user.email,
};
- store
- .dispatch("principal/createPrincipal", newPrincipal)
+ usePrincipalStore()
+ .createPrincipal(newPrincipal)
.then((principal: Principal) => {
const newMember: MemberCreate = {
principalId: principal.id,
@@ -229,7 +234,7 @@ export default defineComponent({
// Note "principal/createdMember" would return the existing role mapping.
// This could happen if another client has just created the role mapping with
// this principal.
- store.dispatch("member/createdMember", newMember);
+ memberStore.createdMember(newMember);
});
useUIStateStore().saveIntroStateByKey({
diff --git a/frontend/src/components/MemberSelect.vue b/frontend/src/components/MemberSelect.vue
index c4907ecac6..d028b2a8ba 100644
--- a/frontend/src/components/MemberSelect.vue
+++ b/frontend/src/components/MemberSelect.vue
@@ -39,7 +39,6 @@
<script lang="ts">
import { reactive, computed, watch, PropType, defineComponent } from "vue";
-import { useStore } from "vuex";
import PrincipalAvatar from "./PrincipalAvatar.vue";
import {
Member,
@@ -50,6 +49,7 @@ import {
} from "../types";
import { isDBA, isDeveloper, isOwner } from "../utils";
import { BBComboBox } from "../bbkit";
+import { useMemberStore, usePrincipalStore } from "@/store";
interface LocalState {
selectedId: PrincipalId | undefined;
@@ -87,10 +87,11 @@ export default defineComponent({
selectedId: props.selectedId,
showMenu: false,
});
- const store = useStore();
+ const memberStore = useMemberStore();
+ const principalStore = usePrincipalStore();
const principalList = computed((): Principal[] => {
- const list = store.getters["member/memberList"]()
+ const list = memberStore.memberList
.filter((member: Member) => {
return member.status == "ACTIVE";
})
@@ -100,7 +101,7 @@ export default defineComponent({
// If system bot is the selected ID (e.g. when issue is created by the bot on observing new sql file),
// Then we add system bot to the list so it can display properly.
if (props.selectedId == SYSTEM_BOT_ID) {
- list.unshift(store.getters["principal/principalById"](SYSTEM_BOT_ID));
+ list.unshift(principalStore.principalById(SYSTEM_BOT_ID));
}
return list.filter((item: Principal) => {
// The previously selected item might no longer be applicable.
diff --git a/frontend/src/components/MemberTable.vue b/frontend/src/components/MemberTable.vue
index 30d4f64f8f..fca9ca6705 100644
--- a/frontend/src/components/MemberTable.vue
+++ b/frontend/src/components/MemberTable.vue
@@ -111,14 +111,13 @@
<script lang="ts">
import { computed, defineComponent, PropType, reactive } from "vue";
-import { useStore } from "vuex";
import { useI18n } from "vue-i18n";
import RoleSelect from "../components/RoleSelect.vue";
import PrincipalAvatar from "../components/PrincipalAvatar.vue";
import { MemberId, RoleType, MemberPatch, Member, RowStatus } from "../types";
import { BBTableColumn, BBTableSectionDataSource } from "../bbkit/types";
import { isOwner } from "../utils";
-import { featureToRef } from "@/store";
+import { featureToRef, useCurrentUser, useMemberStore } from "@/store";
const COLUMN_LIST: BBTableColumn[] = [
{
@@ -149,9 +148,9 @@ export default defineComponent({
},
setup(props) {
const { t } = useI18n();
- const store = useStore();
+ const memberStore = useMemberStore();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const hasRBACFeature = featureToRef("bb.feature.rbac");
@@ -239,7 +238,7 @@ export default defineComponent({
const memberPatch: MemberPatch = {
role,
};
- store.dispatch("member/patchMember", {
+ memberStore.patchMember({
id,
memberPatch,
});
@@ -249,7 +248,7 @@ export default defineComponent({
const memberPatch: MemberPatch = {
rowStatus,
};
- store.dispatch("member/patchMember", {
+ memberStore.patchMember({
id,
memberPatch,
});
diff --git a/frontend/src/components/ProfileDropdown.vue b/frontend/src/components/ProfileDropdown.vue
index a4a8379eca..9240d76b3f 100644
--- a/frontend/src/components/ProfileDropdown.vue
+++ b/frontend/src/components/ProfileDropdown.vue
@@ -122,7 +122,6 @@
<script lang="ts">
import { computed, defineComponent, ref } from "vue";
-import { useStore } from "vuex";
import { useRouter } from "vue-router";
import PrincipalAvatar from "./PrincipalAvatar.vue";
import { ServerInfo } from "../types";
@@ -131,6 +130,7 @@ import { useLanguage } from "../composables/useLanguage";
import {
pushNotification,
useActuatorStore,
+ useAuthStore,
useDebugStore,
useUIStateStore,
} from "@/store";
@@ -141,15 +141,15 @@ export default defineComponent({
components: { PrincipalAvatar },
props: {},
setup() {
- const store = useStore();
const actuatorStore = useActuatorStore();
+ const authStore = useAuthStore();
const debugStore = useDebugStore();
const uiStateStore = useUIStateStore();
const router = useRouter();
const { setLocale, locale } = useLanguage();
const languageMenu = ref();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const { currentUser } = storeToRefs(authStore);
// For now, debug mode is a global setting and will affect all users.
// So we only allow DBA and Owner to toggle it.
@@ -160,7 +160,7 @@ export default defineComponent({
const showQuickstart = computed(() => !actuatorStore.isDemo);
const logout = () => {
- store.dispatch("auth/logout").then(() => {
+ authStore.logout().then(() => {
router.push({ name: "auth.signin" });
});
};
@@ -191,7 +191,8 @@ export default defineComponent({
};
const switchToOwner = () => {
- store.dispatch("auth/login", {
+ authStore.login({
+ authProvider: "BYTEBASE",
payload: {
password: "1024",
@@ -200,7 +201,8 @@ export default defineComponent({
};
const switchToDBA = () => {
- store.dispatch("auth/login", {
+ authStore.login({
+ authProvider: "BYTEBASE",
payload: {
password: "aaa",
@@ -209,7 +211,8 @@ export default defineComponent({
};
const switchToDeveloper = () => {
- store.dispatch("auth/login", {
+ authStore.login({
+ authProvider: "BYTEBASE",
payload: {
password: "aaa",
diff --git a/frontend/src/components/ProjectListSidePanel.vue b/frontend/src/components/ProjectListSidePanel.vue
index 52e3e9068b..c13f9dcb85 100644
--- a/frontend/src/components/ProjectListSidePanel.vue
+++ b/frontend/src/components/ProjectListSidePanel.vue
@@ -8,7 +8,7 @@
</template>
<script lang="ts">
-import { computed, watchEffect } from "vue";
+import { computed, defineComponent, watchEffect } from "vue";
import { useStore } from "vuex";
import { Project, UNKNOWN_ID } from "../types";
@@ -17,8 +17,9 @@ import { BBOutlineItem } from "../bbkit/types";
import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
+import { useCurrentUser } from "@/store";
-export default {
+export default defineComponent({
name: "ProjectListSidePanel",
props: {},
setup() {
@@ -26,7 +27,7 @@ export default {
const store = useStore();
const router = useRouter();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const prepareProjectList = () => {
// It will also be called when user logout
@@ -78,5 +79,5 @@ export default {
outlineItemList,
};
},
-};
+});
</script>
diff --git a/frontend/src/components/ProjectMemberPanel.vue b/frontend/src/components/ProjectMemberPanel.vue
index 68e5257821..19fbe5bdab 100644
--- a/frontend/src/components/ProjectMemberPanel.vue
+++ b/frontend/src/components/ProjectMemberPanel.vue
@@ -173,7 +173,12 @@ import {
} from "../types";
import { isOwner, isProjectOwner } from "../utils";
import { useI18n } from "vue-i18n";
-import { featureToRef, pushNotification } from "@/store";
+import {
+ featureToRef,
+ pushNotification,
+ useCurrentUser,
+ useMemberStore,
+} from "@/store";
interface LocalState {
principalId: PrincipalId;
@@ -198,7 +203,7 @@ export default defineComponent({
const store = useStore();
const { t } = useI18n();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const state = reactive<LocalState>({
principalId: UNKNOWN_ID,
@@ -280,9 +285,7 @@ export default defineComponent({
role: hasRBACFeature.value ? state.role : "OWNER",
roleProvider: "BYTEBASE",
};
- const member = store.getters["member/memberByPrincipalId"](
- state.principalId
- );
+ const member = useMemberStore().memberByPrincipalId(state.principalId);
store
.dispatch("project/createdMember", {
projectId: props.project.id,
diff --git a/frontend/src/components/ProjectMemberTable.vue b/frontend/src/components/ProjectMemberTable.vue
index 49abb62807..b212ea35bf 100644
--- a/frontend/src/components/ProjectMemberTable.vue
+++ b/frontend/src/components/ProjectMemberTable.vue
@@ -134,7 +134,7 @@ import {
import { BBTableColumn, BBTableSectionDataSource } from "../bbkit/types";
import { isOwner, isProjectOwner } from "../utils";
import { useI18n } from "vue-i18n";
-import { featureToRef, pushNotification } from "@/store";
+import { featureToRef, pushNotification, useCurrentUser } from "@/store";
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface LocalState {}
@@ -157,7 +157,7 @@ export default defineComponent({
const store = useStore();
const { t } = useI18n();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const hasRBACFeature = featureToRef("bb.feature.rbac");
diff --git a/frontend/src/components/ProjectSelect.vue b/frontend/src/components/ProjectSelect.vue
index 31d1d796fa..af934de6ab 100644
--- a/frontend/src/components/ProjectSelect.vue
+++ b/frontend/src/components/ProjectSelect.vue
@@ -53,7 +53,6 @@
<script lang="ts">
import {
computed,
- ComputedRef,
defineComponent,
PropType,
reactive,
@@ -62,14 +61,13 @@ import {
} from "vue";
import { useStore } from "vuex";
import {
- Principal,
Project,
UNKNOWN_ID,
DEFAULT_PROJECT_ID,
ProjectRoleType,
} from "../types";
import { isDBAOrOwner } from "../utils";
-import { featureToRef } from "@/store";
+import { featureToRef, useCurrentUser } from "@/store";
interface LocalState {
selectedId: number;
@@ -111,9 +109,7 @@ export default defineComponent({
selectedId: props.selectedId,
});
- const currentUser: ComputedRef<Principal> = computed(() =>
- store.getters["auth/currentUser"]()
- );
+ const currentUser = useCurrentUser();
const prepareProjectList = () => {
store.dispatch("project/fetchProjectListByUser", {
diff --git a/frontend/src/components/ProjectSettingPanel.vue b/frontend/src/components/ProjectSettingPanel.vue
index 35a421703a..14b82888c6 100644
--- a/frontend/src/components/ProjectSettingPanel.vue
+++ b/frontend/src/components/ProjectSettingPanel.vue
@@ -38,14 +38,15 @@
</template>
<script lang="ts">
-import { computed, PropType } from "vue";
+import { computed, defineComponent, PropType } from "vue";
import { useStore } from "vuex";
import { isProjectOwner } from "../utils";
import ProjectGeneralSettingPanel from "../components/ProjectGeneralSettingPanel.vue";
import ProjectMemberPanel from "../components/ProjectMemberPanel.vue";
import { ProjectPatch, Project } from "../types";
+import { useCurrentUser } from "@/store";
-export default {
+export default defineComponent({
name: "ProjectSettingPanel",
components: {
ProjectGeneralSettingPanel,
@@ -64,7 +65,7 @@ export default {
setup(props) {
const store = useStore();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
// Only the project owner can archive/restore the project info.
// This means even the workspace owner won't be able to edit it.
@@ -95,5 +96,5 @@ export default {
archiveOrRestoreProject,
};
},
-};
+});
</script>
diff --git a/frontend/src/components/ProvideDashboardContext.vue b/frontend/src/components/ProvideDashboardContext.vue
index adbae62ceb..71fee078de 100644
--- a/frontend/src/components/ProvideDashboardContext.vue
+++ b/frontend/src/components/ProvideDashboardContext.vue
@@ -3,7 +3,13 @@
</template>
<script lang="ts">
-import { useEnvironmentStore, useSettingStore, useUIStateStore } from "@/store";
+import {
+ useEnvironmentStore,
+ useMemberStore,
+ usePrincipalStore,
+ useSettingStore,
+ useUIStateStore,
+} from "@/store";
import { defineComponent } from "vue";
import { useStore } from "vuex";
import { DEFAULT_PROJECT_ID } from "../types";
@@ -16,12 +22,12 @@ export default defineComponent({
await Promise.all([
useSettingStore().fetchSetting(),
// Fetch so MemberSelect can have the data.
- store.dispatch("member/fetchMemberList"),
+ useMemberStore().fetchMemberList(),
// Though fetchMemberList also return the principal info, it's possible that a principal is no longer a member.
// since all record types have creator, updater which are associated with principal, so we need to fetch
// the principal list as well.
// We also need this to render the proper inbox and activity entry.
- store.dispatch("principal/fetchPrincipalList"),
+ usePrincipalStore().fetchPrincipalList(),
useEnvironmentStore().fetchEnvironmentList(),
// The default project hosts databases not explicitly assigned to other users project.
store.dispatch("project/fetchProjectById", DEFAULT_PROJECT_ID),
diff --git a/frontend/src/components/ProvideSqlEditorContext.vue b/frontend/src/components/ProvideSqlEditorContext.vue
index 72f8402b61..539dde9f8e 100644
--- a/frontend/src/components/ProvideSqlEditorContext.vue
+++ b/frontend/src/components/ProvideSqlEditorContext.vue
@@ -3,7 +3,8 @@
</template>
<script lang="ts" setup>
-import { computed, reactive, onMounted } from "vue";
+import { useCurrentUser } from "@/store";
+import { reactive, onMounted } from "vue";
import { useStore } from "vuex";
import {
Instance,
@@ -28,7 +29,7 @@ const state = reactive<{
databaseIdList: new Map(),
});
-const currentUser = computed(() => store.getters["auth/currentUser"]());
+const currentUser = useCurrentUser();
const prepareAccessibleConnectionByProject = async () => {
// It will also be called when user logout
diff --git a/frontend/src/components/Quickstart.vue b/frontend/src/components/Quickstart.vue
index ba073e532f..f5a371aaeb 100644
--- a/frontend/src/components/Quickstart.vue
+++ b/frontend/src/components/Quickstart.vue
@@ -59,11 +59,15 @@
<script lang="ts">
import { computed, reactive, defineComponent, Ref } from "vue";
-import { useStore } from "vuex";
import { useI18n } from "vue-i18n";
import { isDBA, isOwner } from "../utils";
import { useKBarHandler, useKBarEventOnce } from "@bytebase/vue-kbar";
-import { hasFeature, pushNotification, useUIStateStore } from "@/store";
+import {
+ hasFeature,
+ pushNotification,
+ useCurrentUser,
+ useUIStateStore,
+} from "@/store";
type IntroItem = {
name: string | Ref<string>;
@@ -77,12 +81,11 @@ type IntroItem = {
export default defineComponent({
name: "QuickStart",
setup() {
- const store = useStore();
const uiStateStore = useUIStateStore();
const { t } = useI18n();
const kbarHandler = useKBarHandler();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const introList = reactive<IntroItem[]>([
{
diff --git a/frontend/src/components/RepositoryVCSProviderPanel.vue b/frontend/src/components/RepositoryVCSProviderPanel.vue
index 611c2b46f8..d929b74023 100644
--- a/frontend/src/components/RepositoryVCSProviderPanel.vue
+++ b/frontend/src/components/RepositoryVCSProviderPanel.vue
@@ -43,7 +43,7 @@ import { reactive, computed, watchEffect, onUnmounted, onMounted } from "vue";
import isEmpty from "lodash-es/isEmpty";
import { OAuthWindowEventPayload, openWindowForOAuth, VCS } from "../types";
import { isOwner } from "../utils";
-import { pushNotification } from "@/store";
+import { pushNotification, useCurrentUser } from "@/store";
interface LocalState {
selectedVCS?: VCS;
@@ -58,7 +58,7 @@ const emit = defineEmits<{
const store = useStore();
const state = reactive<LocalState>({});
-const currentUser = computed(() => store.getters["auth/currentUser"]());
+const currentUser = useCurrentUser();
const prepareVCSList = () => {
store.dispatch("vcs/fetchVCSList");
diff --git a/frontend/src/components/RequestDatabasePrepForm.vue b/frontend/src/components/RequestDatabasePrepForm.vue
index c76591a68b..7d5b223f9f 100644
--- a/frontend/src/components/RequestDatabasePrepForm.vue
+++ b/frontend/src/components/RequestDatabasePrepForm.vue
@@ -143,7 +143,7 @@ import DatabaseSelect from "../components/DatabaseSelect.vue";
import EnvironmentSelect from "../components/EnvironmentSelect.vue";
import { DatabaseId, EnvironmentId, ProjectId, UNKNOWN_ID } from "../types";
import { allowDatabaseAccess } from "../utils";
-import { useEnvironmentStore } from "@/store";
+import { useCurrentUser, useEnvironmentStore } from "@/store";
interface LocalState {
environmentId: EnvironmentId;
@@ -164,7 +164,7 @@ export default defineComponent({
const store = useStore();
const router = useRouter();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const keyboardHandler = (e: KeyboardEvent) => {
if (e.code == "Escape") {
diff --git a/frontend/src/components/TransferDatabaseForm.vue b/frontend/src/components/TransferDatabaseForm.vue
index 8467fd4b64..548e380b93 100644
--- a/frontend/src/components/TransferDatabaseForm.vue
+++ b/frontend/src/components/TransferDatabaseForm.vue
@@ -111,7 +111,7 @@ import {
DatabaseLabel,
} from "../types";
import { sortDatabaseList } from "../utils";
-import { pushNotification, useEnvironmentList } from "@/store";
+import { pushNotification, useCurrentUser, useEnvironmentList } from "@/store";
type TransferSource = "DEFAULT" | "OTHER";
@@ -141,7 +141,7 @@ export default defineComponent({
props.projectId == DEFAULT_PROJECT_ID ? "OTHER" : "DEFAULT",
});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const prepareDatabaseListForDefaultProject = () => {
store.dispatch(
diff --git a/frontend/src/layouts/BodyLayout.vue b/frontend/src/layouts/BodyLayout.vue
index a8579554c6..2cd8ffde4a 100644
--- a/frontend/src/layouts/BodyLayout.vue
+++ b/frontend/src/layouts/BodyLayout.vue
@@ -139,7 +139,6 @@
<script lang="ts">
import { computed, defineComponent, reactive } from "vue";
-import { useStore } from "vuex";
import { useRouter } from "vue-router";
import Breadcrumb from "../components/Breadcrumb.vue";
import IntroBanner from "../components/IntroBanner.vue";
@@ -150,6 +149,7 @@ import { isDBA, isDeveloper, isOwner } from "../utils";
import { PlanType } from "../types";
import {
useActuatorStore,
+ useCurrentUser,
useSubscriptionStore,
useUIStateStore,
} from "@/store";
@@ -167,7 +167,6 @@ export default defineComponent({
QuickActionPanel,
},
setup() {
- const store = useStore();
const actuatorStore = useActuatorStore();
const subscriptionStore = useSubscriptionStore();
const uiStateStore = useUIStateStore();
@@ -177,7 +176,7 @@ export default defineComponent({
showMobileOverlay: false,
});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const quickActionList = computed(() => {
const role = currentUser.value.role;
diff --git a/frontend/src/layouts/DashboardLayout.vue b/frontend/src/layouts/DashboardLayout.vue
index 6a1b82b9f5..ae125ec55d 100644
--- a/frontend/src/layouts/DashboardLayout.vue
+++ b/frontend/src/layouts/DashboardLayout.vue
@@ -45,7 +45,6 @@
</template>
<script lang="ts">
-import { useStore } from "vuex";
import ProvideDashboardContext from "../components/ProvideDashboardContext.vue";
import DashboardHeader from "../views/DashboardHeader.vue";
import BannerDemo from "../views/BannerDemo.vue";
@@ -57,6 +56,7 @@ import { computed, defineComponent } from "vue";
import {
pushNotification,
useActuatorStore,
+ useCurrentUser,
useDebugStore,
useSubscriptionStore,
} from "@/store";
@@ -72,7 +72,6 @@ export default defineComponent({
BannerDebug,
},
setup() {
- const store = useStore();
const actuatorStore = useActuatorStore();
const subscriptionStore = useSubscriptionStore();
const debugStore = useDebugStore();
@@ -92,7 +91,7 @@ export default defineComponent({
const { isDebug } = storeToRefs(debugStore);
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
// For now, debug mode is a global setting and will affect all users.
// So we only allow DBA and Owner to toggle it and thus show a banner
diff --git a/frontend/src/layouts/ProjectLayout.vue b/frontend/src/layouts/ProjectLayout.vue
index 874baa9492..eb6c1bf694 100644
--- a/frontend/src/layouts/ProjectLayout.vue
+++ b/frontend/src/layouts/ProjectLayout.vue
@@ -41,6 +41,7 @@ import ArchiveBanner from "../components/ArchiveBanner.vue";
import { BBTabFilterItem } from "../bbkit/types";
import { useI18n } from "vue-i18n";
import { Project } from "../types";
+import { useCurrentUser } from "@/store";
type ProjectTabItem = {
name: string;
@@ -71,7 +72,7 @@ export default defineComponent({
const router = useRouter();
const { t } = useI18n();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const project = computed((): Project => {
return store.getters["project/projectById"](
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 1c859c38d7..c36200b517 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -20,6 +20,7 @@ import {
pinia,
pushNotification,
useActuatorStore,
+ useAuthStore,
useSubscriptionStore,
} from "./store";
import {
@@ -80,7 +81,7 @@ axios.interceptors.response.use(
const host = useActuatorStore().info?.host;
if (host && error.response.request.responseURL.startsWith(host))
try {
- await store.dispatch("auth/logout");
+ await useAuthStore().logout();
} finally {
router.push({ name: "auth.signin" });
}
@@ -153,10 +154,10 @@ const initSubscription = () => {
const subscriptionStore = useSubscriptionStore();
return subscriptionStore.fetchSubscription();
};
-Promise.all([
- initActuator(),
- initSubscription(),
- store.dispatch("auth/restoreUser"),
-]).finally(() => {
+const restoreUser = () => {
+ const authStore = useAuthStore();
+ return authStore.restoreUser();
+};
+Promise.all([initActuator(), initSubscription(), restoreUser()]).finally(() => {
app.mount("#app");
});
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 9e175bc6d8..3f8f228bd3 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -12,7 +12,13 @@ import InstanceLayout from "../layouts/InstanceLayout.vue";
import SplashLayout from "../layouts/SplashLayout.vue";
import SqlEditorLayout from "../layouts/SqlEditorLayout.vue";
import { t } from "../plugins/i18n";
-import { store, useEnvironmentStore, useRouterStore } from "../store";
+import {
+ store,
+ useAuthStore,
+ useEnvironmentStore,
+ usePrincipalStore,
+ useRouterStore,
+} from "../store";
import { Database, QuickActionType, Sheet, UNKNOWN_ID } from "../types";
import { idFromSlug, isDBAOrOwner, isOwner } from "../utils";
// import PasswordReset from "../views/auth/PasswordReset.vue";
@@ -234,9 +240,11 @@ const routes: Array<RouteRecordRaw> = [
name: "workspace.profile",
meta: {
title: (route: RouteLocationNormalized) => {
- const principalId = route.params.principalId as string;
- return store.getters["principal/principalById"](principalId)
- .name;
+ const principalId = parseInt(
+ route.params.principalId as string,
+ 10
+ );
+ return usePrincipalStore().principalById(principalId).name;
},
},
components: {
@@ -458,7 +466,7 @@ const routes: Array<RouteRecordRaw> = [
);
if (project.rowStatus == "NORMAL") {
- const currentUser = store.getters["auth/currentUser"]();
+ const currentUser = useAuthStore().currentUser;
let allowEditProject = false;
if (isDBAOrOwner(currentUser.role)) {
allowEditProject = true;
@@ -795,11 +803,12 @@ export const router = createRouter({
router.beforeEach((to, from, next) => {
console.debug("Router %s -> %s", from.name, to.name);
+ const authStore = useAuthStore();
const environmentStore = useEnvironmentStore();
const tabStore = useTabStore();
const routerStore = useRouterStore();
- const isLoggedIn = store.getters["auth/isLoggedIn"]();
+ const isLoggedIn = authStore.isLoggedIn();
const fromModule = from.name
? from.name.toString().split(".")[0]
@@ -849,7 +858,7 @@ router.beforeEach((to, from, next) => {
}
}
- const currentUser = store.getters["auth/currentUser"]();
+ const currentUser = authStore.currentUser;
if (to.name?.toString().startsWith("setting.workspace.version-control")) {
// Returns 403 immediately if not Owner. Otherwise, we may need to fetch the VCS detail
@@ -933,8 +942,8 @@ router.beforeEach((to, from, next) => {
const sheetSlug = routerSlug.sheetSlug;
if (principalId) {
- store
- .dispatch("principal/fetchPrincipalById", principalId)
+ usePrincipalStore()
+ .fetchPrincipalById(principalId)
.then(() => {
next();
})
diff --git a/frontend/src/store/modules/activity.ts b/frontend/src/store/modules/activity.ts
index d55484c5ae..22be41a93c 100644
--- a/frontend/src/store/modules/activity.ts
+++ b/frontend/src/store/modules/activity.ts
@@ -10,7 +10,7 @@ import {
ProjectId,
ResourceObject,
} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
+import { useAuthStore, getPrincipalFromIncludedList } from "../pinia";
function convert(
activity: ResourceObject,
@@ -117,7 +117,7 @@ const actions = {
limit: number;
}
) {
- const currentUser = rootGetters["auth/currentUser"]();
+ const { currentUser } = useAuthStore();
const queryList = [
"type=bb.sql-editor.query",
`user=${currentUser.id}`,
diff --git a/frontend/src/store/modules/auth.ts b/frontend/src/store/modules/auth.ts
deleted file mode 100644
index a1174833bf..0000000000
--- a/frontend/src/store/modules/auth.ts
+++ /dev/null
@@ -1,165 +0,0 @@
-import axios from "axios";
-import isEqual from "lodash-es/isEqual";
-import {
- Principal,
- AuthState,
- LoginInfo,
- SignupInfo,
- ActivateInfo,
- ResourceObject,
- unknown,
- PrincipalId,
- AuthProvider,
-} from "../../types";
-import { getIntCookie } from "../../utils";
-
-function convert(user: ResourceObject, rootGetters: any): Principal {
- return rootGetters["principal/principalById"](user.id);
-}
-
-function convertAuthProvider(authProvider: ResourceObject) {
- return { ...authProvider.attributes };
-}
-
-const state: () => AuthState = () => ({
- authProviderList: [],
- currentUser: unknown("PRINCIPAL") as Principal,
-});
-
-const getters = {
- authProviderList: (state: AuthState) => (): AuthProvider[] => {
- return state.authProviderList;
- },
-
- isLoggedIn: (state: AuthState) => (): boolean => {
- return getIntCookie("user") != undefined;
- },
-
- currentUser: (state: AuthState) => (): Principal => {
- return state.currentUser;
- },
-};
-
-const actions = {
- async fetchProviderList({ commit }: any) {
- const providerList = (await axios.get("/api/auth/provider")).data.data;
- const convertedProviderList = providerList.map(
- (provider: ResourceObject) => {
- return convertAuthProvider(provider);
- }
- );
- commit("setAuthProviderList", convertedProviderList);
- return convertedProviderList;
- },
-
- async login({ commit, dispatch, rootGetters }: any, loginInfo: LoginInfo) {
- const loggedInUser = (
- await axios.post(`/api/auth/login/${loginInfo.authProvider}`, {
- data: { type: "loginInfo", attributes: loginInfo.payload },
- })
- ).data.data;
-
- // Refresh the corresponding principal
- await dispatch("principal/fetchPrincipalById", loggedInUser.id, {
- root: true,
- });
-
- // The conversion relies on the above refresh.
- const convertedUser = convert(loggedInUser, rootGetters);
- commit("setCurrentUser", convertedUser);
- return convertedUser;
- },
-
- async logout({ commit }: any) {
- try {
- await axios.post("/api/auth/logout");
- } finally {
- commit("setCurrentUser", unknown("PRINCIPAL") as Principal);
- }
- return unknown("PRINCIPAL") as Principal;
- },
-
- async signup({ commit, dispatch, rootGetters }: any, signupInfo: SignupInfo) {
- const newUser = (
- await axios.post("/api/auth/signup", {
- data: { type: "signupInfo", attributes: signupInfo },
- })
- ).data.data;
-
- // Refresh the corresponding principal
- await dispatch("principal/fetchPrincipalById", newUser.id, { root: true });
-
- // The conversion relies on the above refresh.
- const convertedUser = convert(newUser, rootGetters);
- commit("setCurrentUser", convertedUser);
- return convertedUser;
- },
-
- async activate(
- { commit, dispatch, rootGetters }: any,
- activateInfo: ActivateInfo
- ) {
- const activatedUser = (
- await axios.post("/api/auth/activate", {
- data: { type: "activateInfo", attributes: activateInfo },
- })
- ).data.data;
-
- // Refresh the corresponding principal
- dispatch("principal/fetchPrincipalById", activatedUser.id, { root: true });
-
- // The conversion relies on the above task to get the lastest data
- const convertedUser = convert(activatedUser, rootGetters);
- commit("setCurrentUser", convertedUser);
- return convertedUser;
- },
-
- async restoreUser({ commit, dispatch }: any) {
- const userId = getIntCookie("user");
- if (userId) {
- const loggedInUser = await dispatch(
- "principal/fetchPrincipalById",
- userId,
- {
- root: true,
- }
- );
-
- commit("setCurrentUser", loggedInUser);
- return loggedInUser;
- }
- return unknown("PRINCIPAL") as Principal;
- },
-
- async refreshUserIfNeeded(
- { commit, state, rootGetters }: any,
- principalId: PrincipalId
- ) {
- if (principalId == state.currentUser.id) {
- const refreshedUser = rootGetters["principal/principalById"](
- state.currentUser.id
- );
- if (!isEqual(refreshedUser, state.currentUser)) {
- commit("setCurrentUser", refreshedUser);
- }
- }
- },
-};
-
-const mutations = {
- setAuthProviderList(state: AuthState, authProviderList: AuthProvider[]) {
- state.authProviderList = authProviderList;
- },
-
- setCurrentUser(state: AuthState, user: Principal) {
- state.currentUser = user;
- },
-};
-
-export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations,
-};
diff --git a/frontend/src/store/modules/dataSource.ts b/frontend/src/store/modules/dataSource.ts
index 8a5246d255..146dc74497 100644
--- a/frontend/src/store/modules/dataSource.ts
+++ b/frontend/src/store/modules/dataSource.ts
@@ -11,7 +11,7 @@ import {
EMPTY_ID,
empty,
} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
+import { getPrincipalFromIncludedList } from "../pinia";
function convert(
dataSource: ResourceObject,
@@ -94,12 +94,15 @@ const actions = {
newDataSource: DataSourceCreate
) {
const data = (
- await axios.post(`/api/database/${newDataSource.databaseId}/data-source`, {
- data: {
- type: "DataSourceCreate",
- attributes: newDataSource,
- },
- })
+ await axios.post(
+ `/api/database/${newDataSource.databaseId}/data-source`,
+ {
+ data: {
+ type: "DataSourceCreate",
+ attributes: newDataSource,
+ },
+ }
+ )
).data;
const createdDataSource = convert(data.data, data.included, rootGetters);
diff --git a/frontend/src/store/modules/database.ts b/frontend/src/store/modules/database.ts
index 21c2875525..425228cd32 100644
--- a/frontend/src/store/modules/database.ts
+++ b/frontend/src/store/modules/database.ts
@@ -20,7 +20,7 @@ import {
ResourceObject,
unknown,
} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
+import { getPrincipalFromIncludedList } from "../pinia-modules/principal";
import { useBackupStore, useAnomalyStore } from "@/store";
function convert(
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
index 28ad81a3d5..aa011557c8 100644
--- a/frontend/src/store/modules/instance.ts
+++ b/frontend/src/store/modules/instance.ts
@@ -22,8 +22,10 @@ import {
unknown,
} from "../../types";
import { InstanceUser } from "../../types/InstanceUser";
-import { useEnvironmentStore } from "../pinia-modules";
-import { getPrincipalFromIncludedList } from "./principal";
+import {
+ getPrincipalFromIncludedList,
+ useEnvironmentStore,
+} from "../pinia-modules";
import { useAnomalyStore } from "@/store";
function convert(
diff --git a/frontend/src/store/modules/issue.ts b/frontend/src/store/modules/issue.ts
index e008e2deb9..29dfebdf06 100644
--- a/frontend/src/store/modules/issue.ts
+++ b/frontend/src/store/modules/issue.ts
@@ -18,7 +18,7 @@ import {
ResourceObject,
unknown,
} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
+import { getPrincipalFromIncludedList } from "../pinia";
function convert(
issue: ResourceObject,
diff --git a/frontend/src/store/modules/member.ts b/frontend/src/store/modules/member.ts
deleted file mode 100644
index 5aa9562bd4..0000000000
--- a/frontend/src/store/modules/member.ts
+++ /dev/null
@@ -1,172 +0,0 @@
-import axios from "axios";
-import {
- Member,
- MemberId,
- MemberCreate,
- MemberPatch,
- MemberState,
- ResourceObject,
- PrincipalId,
- unknown,
- empty,
- EMPTY_ID,
- RoleType,
-} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
-
-function convert(
- member: ResourceObject,
- includedList: ResourceObject[],
- rootGetters: any
-): Member {
- const principal = getPrincipalFromIncludedList(
- member.relationships!.principal.data,
- includedList
- );
- principal.role = member.attributes.role as RoleType;
-
- return {
- ...(member.attributes as Omit<
- Member,
- "id" | "principal" | "creator" | "updater"
- >),
- id: parseInt(member.id),
- creator: getPrincipalFromIncludedList(
- member.relationships!.creator.data,
- includedList
- ),
- updater: getPrincipalFromIncludedList(
- member.relationships!.updater.data,
- includedList
- ),
- principal: principal,
- };
-}
-
-const state: () => MemberState = () => ({
- memberList: [],
-});
-
-const getters = {
- memberList: (state: MemberState) => (): Member[] => {
- return state.memberList;
- },
-
- memberByPrincipalId:
- (state: MemberState) =>
- (id: PrincipalId): Member => {
- if (id == EMPTY_ID) {
- return empty("MEMBER") as Member;
- }
-
- return (
- state.memberList.find((item) => item.principal.id == id) ||
- (unknown("MEMBER") as Member)
- );
- },
-
- memberByEmail:
- (state: MemberState) =>
- (email: string): Member => {
- return (
- state.memberList.find((item) => item.principal.email == email) ||
- (unknown("MEMBER") as Member)
- );
- },
-};
-
-const actions = {
- async fetchMemberList({ commit, rootGetters }: any) {
- const data = (await axios.get(`/api/member`)).data;
- const memberList = data.data.map((member: ResourceObject) => {
- return convert(member, data.included, rootGetters);
- });
-
- // sort the member list
- memberList.sort((a: Member, b: Member) => {
- if (a.createdTs === b.createdTs) {
- return a.id - b.id;
- }
- return a.createdTs - b.createdTs;
- });
-
- commit("setMemberList", memberList);
- return memberList;
- },
-
- // Returns existing member if the principalId has already been created.
- async createdMember({ commit, rootGetters }: any, newMember: MemberCreate) {
- const data = (
- await axios.post(`/api/member`, {
- data: {
- type: "MemberCreate",
- attributes: newMember,
- },
- })
- ).data;
- const createdMember = convert(data.data, data.included, rootGetters);
-
- commit("appendMember", createdMember);
-
- return createdMember;
- },
-
- async patchMember(
- { commit, rootGetters }: any,
- { id, memberPatch }: { id: MemberId; memberPatch: MemberPatch }
- ) {
- const data = (
- await axios.patch(`/api/member/${id}`, {
- data: {
- type: "memberPatch",
- attributes: memberPatch,
- },
- })
- ).data;
- const updatedMember = convert(data.data, data.included, rootGetters);
-
- commit("replaceMemberInList", updatedMember);
-
- return updatedMember;
- },
-
- async deleteMemberById(
- { state, commit }: { state: MemberState; commit: any },
- id: MemberId
- ) {
- await axios.delete(`/api/member/${id}`);
-
- const newList = state.memberList.filter((item: Member) => {
- return item.id != id;
- });
-
- commit("setMemberList", newList);
- },
-};
-
-const mutations = {
- setMemberList(state: MemberState, memberList: Member[]) {
- state.memberList = memberList;
- },
-
- appendMember(state: MemberState, newMember: Member) {
- state.memberList.push(newMember);
- },
-
- replaceMemberInList(state: MemberState, updatedMember: Member) {
- const i = state.memberList.findIndex(
- (item: Member) => item.id == updatedMember.id
- );
- if (i != -1) {
- state.memberList[i] = updatedMember;
- }
- },
-};
-
-export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations,
-};
diff --git a/frontend/src/store/modules/pipeline.ts b/frontend/src/store/modules/pipeline.ts
index bc121fa769..a89ebc4183 100644
--- a/frontend/src/store/modules/pipeline.ts
+++ b/frontend/src/store/modules/pipeline.ts
@@ -5,7 +5,7 @@ import {
PipelineState,
Stage,
} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
+import { getPrincipalFromIncludedList } from "../pinia";
const state: () => PipelineState = () => ({});
diff --git a/frontend/src/store/modules/principal.ts b/frontend/src/store/modules/principal.ts
deleted file mode 100644
index a365e53b46..0000000000
--- a/frontend/src/store/modules/principal.ts
+++ /dev/null
@@ -1,183 +0,0 @@
-import axios from "axios";
-import {
- PrincipalId,
- Principal,
- PrincipalCreate,
- PrincipalPatch,
- PrincipalState,
- ResourceObject,
- unknown,
- empty,
- EMPTY_ID,
- PrincipalType,
- ResourceIdentifier,
- RoleType,
-} from "../../types";
-import { randomString } from "../../utils";
-
-function convert(principal: ResourceObject): Principal {
- return {
- id: parseInt(principal.id),
- creatorId: principal.attributes.creatorId as PrincipalId,
- createdTs: principal.attributes.createdTs as number,
- updaterId: principal.attributes.updaterId as PrincipalId,
- updatedTs: principal.attributes.updatedTs as number,
- type: principal.attributes.type as PrincipalType,
- name: principal.attributes.name as string,
- email: principal.attributes.email as string,
- role: principal.attributes.role as RoleType,
- };
-}
-
-export function getPrincipalFromIncludedList(
- data:
- | ResourceIdentifier<ResourceObject>
- | ResourceIdentifier<ResourceObject>[]
- | undefined,
- includedList: ResourceObject[]
-): Principal {
- if (data == null) {
- return empty("PRINCIPAL") as Principal;
- }
- for (const item of includedList || []) {
- if (item.type != "principal") {
- continue;
- }
- if (item.id == (data as ResourceIdentifier).id) {
- return convert(item);
- }
- }
- return empty("PRINCIPAL") as Principal;
-}
-
-const state: () => PrincipalState = () => ({
- principalList: [],
-});
-
-const getters = {
- convert:
- (state: PrincipalState, getters: any, rootState: any, rootGetters: any) =>
- (principal: ResourceObject, includedList: ResourceObject[]): Principal => {
- return convert(principal);
- },
-
- principalList: (state: PrincipalState) => (): Principal[] => {
- return state.principalList;
- },
-
- principalById:
- (state: PrincipalState) =>
- (principalId: PrincipalId): Principal => {
- if (principalId == EMPTY_ID) {
- return empty("PRINCIPAL") as Principal;
- }
-
- return (
- state.principalList.find((item) => item.id == principalId) ||
- (unknown("PRINCIPAL") as Principal)
- );
- },
-};
-
-const actions = {
- async fetchPrincipalList({ commit }: any) {
- const userList: ResourceObject[] = (await axios.get(`/api/principal`)).data
- .data;
- const principalList = userList.map((user) => {
- return convert(user);
- });
-
- commit("setPrincipalList", principalList);
-
- return principalList;
- },
-
- async fetchPrincipalById({ commit }: any, principalId: PrincipalId) {
- const principal = convert(
- (await axios.get(`/api/principal/${principalId}`)).data.data
- );
-
- commit("upsertPrincipalInList", principal);
-
- return principal;
- },
-
- // Returns existing user if already created.
- async createPrincipal({ commit }: any, newPrincipal: PrincipalCreate) {
- const createdPrincipal = convert(
- (
- await axios.post(`/api/principal`, {
- data: {
- type: "PrincipalCreate",
- attributes: {
- name: newPrincipal.name,
- email: newPrincipal.email,
- password: randomString(),
- },
- },
- })
- ).data.data
- );
-
- commit("appendPrincipal", createdPrincipal);
-
- return createdPrincipal;
- },
-
- async patchPrincipal(
- { commit, dispatch }: any,
- {
- principalId,
- principalPatch,
- }: {
- principalId: PrincipalId;
- principalPatch: PrincipalPatch;
- }
- ) {
- const updatedPrincipal = convert(
- (
- await axios.patch(`/api/principal/${principalId}`, {
- data: {
- type: "principalPatch",
- attributes: principalPatch,
- },
- })
- ).data.data
- );
-
- commit("upsertPrincipalInList", updatedPrincipal);
-
- dispatch("auth/refreshUserIfNeeded", updatedPrincipal.id, { root: true });
-
- return updatedPrincipal;
- },
-};
-
-const mutations = {
- setPrincipalList(state: PrincipalState, principalList: Principal[]) {
- state.principalList = principalList;
- },
-
- appendPrincipal(state: PrincipalState, newPrincipal: Principal) {
- state.principalList.push(newPrincipal);
- },
-
- upsertPrincipalInList(state: PrincipalState, updatedPrincipal: Principal) {
- const i = state.principalList.findIndex(
- (item: Principal) => item.id == updatedPrincipal.id
- );
- if (i == -1) {
- state.principalList.push(updatedPrincipal);
- } else {
- state.principalList[i] = updatedPrincipal;
- }
- },
-};
-
-export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations,
-};
diff --git a/frontend/src/store/modules/project.ts b/frontend/src/store/modules/project.ts
index 8f084ae23f..604813b1e2 100644
--- a/frontend/src/store/modules/project.ts
+++ b/frontend/src/store/modules/project.ts
@@ -18,7 +18,7 @@ import {
RowStatus,
unknown,
} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
+import { getPrincipalFromIncludedList } from "../pinia";
function convert(
project: ResourceObject,
diff --git a/frontend/src/store/modules/projectWebhook.ts b/frontend/src/store/modules/projectWebhook.ts
index ed664dd84a..590286fe8b 100644
--- a/frontend/src/store/modules/projectWebhook.ts
+++ b/frontend/src/store/modules/projectWebhook.ts
@@ -10,7 +10,7 @@ import {
ResourceObject,
unknown,
} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
+import { getPrincipalFromIncludedList } from "../pinia";
function convert(
projectWebhook: ResourceObject,
diff --git a/frontend/src/store/modules/repository.ts b/frontend/src/store/modules/repository.ts
index eb73391bfe..e29b476a81 100644
--- a/frontend/src/store/modules/repository.ts
+++ b/frontend/src/store/modules/repository.ts
@@ -12,7 +12,7 @@ import {
VCS,
VCSId,
} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
+import { getPrincipalFromIncludedList } from "../pinia";
function convert(
repository: ResourceObject,
diff --git a/frontend/src/store/modules/sheet.ts b/frontend/src/store/modules/sheet.ts
index 318ff5de1b..f3267e19ac 100644
--- a/frontend/src/store/modules/sheet.ts
+++ b/frontend/src/store/modules/sheet.ts
@@ -17,7 +17,8 @@ import type {
ProjectMember,
} from "@/types";
import { unknown, UNKNOWN_ID } from "@/types";
-import { getPrincipalFromIncludedList } from "./principal";
+import { getPrincipalFromIncludedList } from "../pinia";
+import { useAuthStore } from "../pinia-modules";
function convertSheet(
sheet: ResourceObject,
@@ -75,7 +76,7 @@ const getters = {
isCreator:
(state: SheetState, getters: any, rootState: any, rootGetters: any) =>
(currentTab: TabInfo): boolean => {
- const currentUser = rootGetters["auth/currentUser"]();
+ const { currentUser } = useAuthStore();
const currentSheet = getters.currentSheet(currentTab);
if (!currentSheet) return false;
@@ -93,7 +94,7 @@ const getters = {
isReadOnly:
(state: SheetState, getters: any, rootState: any, rootGetters: any) =>
(currentTab: TabInfo): boolean => {
- const currentUser = rootGetters["auth/currentUser"]();
+ const { currentUser } = useAuthStore();
const sharedSheet = rootState.sqlEditor.sharedSheet;
const currentSheet = getters.currentSheet(currentTab);
const isSharedByOthers = sharedSheet.id !== UNKNOWN_ID;
diff --git a/frontend/src/store/modules/stage.ts b/frontend/src/store/modules/stage.ts
index 5cd31c7b73..6e394d9eb2 100644
--- a/frontend/src/store/modules/stage.ts
+++ b/frontend/src/store/modules/stage.ts
@@ -9,8 +9,10 @@ import {
Pipeline,
Environment,
} from "../../types";
-import { useEnvironmentStore } from "../pinia-modules";
-import { getPrincipalFromIncludedList } from "./principal";
+import {
+ getPrincipalFromIncludedList,
+ useEnvironmentStore,
+} from "../pinia-modules";
const state: () => StageState = () => ({});
diff --git a/frontend/src/store/modules/table.ts b/frontend/src/store/modules/table.ts
index ec33a9060a..1b971b5200 100644
--- a/frontend/src/store/modules/table.ts
+++ b/frontend/src/store/modules/table.ts
@@ -8,7 +8,7 @@ import {
TableState,
unknown,
} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
+import { getPrincipalFromIncludedList } from "../pinia";
function convert(
table: ResourceObject,
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.ts
index 2081f82a84..e05d86ac88 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/modules/task.ts
@@ -18,7 +18,7 @@ import {
TaskStatusPatch,
unknown,
} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
+import { getPrincipalFromIncludedList } from "../pinia";
const state: () => TaskState = () => ({});
diff --git a/frontend/src/store/modules/vcs.ts b/frontend/src/store/modules/vcs.ts
index 362d6beb50..6aeccb679b 100644
--- a/frontend/src/store/modules/vcs.ts
+++ b/frontend/src/store/modules/vcs.ts
@@ -10,7 +10,7 @@ import {
empty,
EMPTY_ID,
} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
+import { getPrincipalFromIncludedList } from "../pinia";
function convert(vcs: ResourceObject, includedList: ResourceObject[]): VCS {
return {
diff --git a/frontend/src/store/modules/view.ts b/frontend/src/store/modules/view.ts
index ab98051dab..88bf62a0c6 100644
--- a/frontend/src/store/modules/view.ts
+++ b/frontend/src/store/modules/view.ts
@@ -8,7 +8,7 @@ import {
View,
ViewState,
} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
+import { getPrincipalFromIncludedList } from "../pinia";
function convert(
view: ResourceObject,
diff --git a/frontend/src/store/pinia-modules/anomaly.ts b/frontend/src/store/pinia-modules/anomaly.ts
index 7dd03e9fc9..95163d767a 100644
--- a/frontend/src/store/pinia-modules/anomaly.ts
+++ b/frontend/src/store/pinia-modules/anomaly.ts
@@ -1,6 +1,6 @@
import { defineStore } from "pinia";
-import { Anomaly, ResourceObject } from "../../types";
-import { getPrincipalFromIncludedList } from "@/store/modules/principal";
+import { Anomaly, ResourceObject } from "@/types";
+import { getPrincipalFromIncludedList } from "./principal";
function convert(
anomaly: ResourceObject,
diff --git a/frontend/src/store/pinia-modules/auth.ts b/frontend/src/store/pinia-modules/auth.ts
new file mode 100644
index 0000000000..55aa0f107e
--- /dev/null
+++ b/frontend/src/store/pinia-modules/auth.ts
@@ -0,0 +1,133 @@
+import axios from "axios";
+import { isEqual } from "lodash-es";
+import {
+ Principal,
+ AuthState,
+ LoginInfo,
+ SignupInfo,
+ ActivateInfo,
+ ResourceObject,
+ unknown,
+ PrincipalId,
+ AuthProvider,
+} from "@/types";
+import { getIntCookie } from "@/utils";
+import { defineStore, storeToRefs } from "pinia";
+import { usePrincipalStore } from "./principal";
+import { Ref } from "vue";
+
+function convert(user: ResourceObject): Principal {
+ return usePrincipalStore().principalById(parseInt(user.id, 10));
+}
+
+function convertAuthProvider(authProvider: ResourceObject) {
+ return { ...authProvider.attributes } as AuthProvider;
+}
+
+export const useAuthStore = defineStore("auth", {
+ state: (): AuthState => ({
+ authProviderList: [],
+ currentUser: unknown("PRINCIPAL") as Principal,
+ }),
+ actions: {
+ isLoggedIn: () => {
+ return getIntCookie("user") != undefined;
+ },
+ setAuthProviderList(authProviderList: AuthProvider[]) {
+ this.authProviderList = authProviderList;
+ },
+ setCurrentUser(user: Principal) {
+ this.currentUser = user;
+ },
+ async fetchProviderList() {
+ const providerList = (await axios.get("/api/auth/provider")).data.data;
+ const convertedProviderList: AuthProvider[] = providerList.map(
+ (provider: ResourceObject) => {
+ return convertAuthProvider(provider);
+ }
+ );
+ this.setAuthProviderList(convertedProviderList);
+ return convertedProviderList;
+ },
+ async login(loginInfo: LoginInfo) {
+ const loggedInUser = (
+ await axios.post(`/api/auth/login/${loginInfo.authProvider}`, {
+ data: { type: "loginInfo", attributes: loginInfo.payload },
+ })
+ ).data.data;
+
+ // Refresh the corresponding principal
+ await usePrincipalStore().fetchPrincipalById(loggedInUser.id);
+
+ // The conversion relies on the above refresh.
+ const convertedUser = convert(loggedInUser);
+ this.setCurrentUser(convertedUser);
+ return convertedUser;
+ },
+ async logout() {
+ const unknownPrinciple = unknown("PRINCIPAL") as Principal;
+ try {
+ await axios.post("/api/auth/logout");
+ } finally {
+ this.setCurrentUser(unknownPrinciple);
+ }
+ return unknownPrinciple;
+ },
+ async signup(signupInfo: SignupInfo) {
+ const newUser = (
+ await axios.post("/api/auth/signup", {
+ data: { type: "signupInfo", attributes: signupInfo },
+ })
+ ).data.data;
+
+ // Refresh the corresponding principal
+ await usePrincipalStore().fetchPrincipalById(newUser.id);
+
+ // The conversion relies on the above refresh.
+ const convertedUser = convert(newUser);
+ this.setCurrentUser(convertedUser);
+ return convertedUser;
+ },
+ async activate(activateInfo: ActivateInfo) {
+ const activatedUser = (
+ await axios.post("/api/auth/activate", {
+ data: { type: "activateInfo", attributes: activateInfo },
+ })
+ ).data.data;
+
+ // Refresh the corresponding principal
+ await usePrincipalStore().fetchPrincipalById(activatedUser.id);
+
+ // The conversion relies on the above task to get the latest data
+ const convertedUser = convert(activatedUser);
+ this.setCurrentUser(convertedUser);
+ return convertedUser;
+ },
+ async restoreUser() {
+ const userId = getIntCookie("user");
+ if (userId) {
+ const loggedInUser = await usePrincipalStore().fetchPrincipalById(
+ userId
+ );
+
+ this.setCurrentUser(loggedInUser);
+ return loggedInUser;
+ }
+ return unknown("PRINCIPAL") as Principal;
+ },
+ async refreshUserIfNeeded(principalId: PrincipalId) {
+ if (principalId == this.currentUser.id) {
+ const refreshedUser = usePrincipalStore().principalById(
+ this.currentUser.id
+ );
+ if (!isEqual(refreshedUser, this.currentUser)) {
+ this.setCurrentUser(refreshedUser);
+ }
+ }
+ },
+ },
+});
+
+export const useCurrentUser = (): Ref<Principal> => {
+ return storeToRefs(useAuthStore()).currentUser;
+};
diff --git a/frontend/src/store/pinia-modules/backup.ts b/frontend/src/store/pinia-modules/backup.ts
index 2ad75d9cac..571ba8713d 100644
--- a/frontend/src/store/pinia-modules/backup.ts
+++ b/frontend/src/store/pinia-modules/backup.ts
@@ -11,7 +11,7 @@ import {
ResourceObject,
unknown,
} from "../../types";
-import { getPrincipalFromIncludedList } from "@/store/modules/principal";
+import { getPrincipalFromIncludedList } from "./principal";
export function convertBackup(
backup: ResourceObject,
diff --git a/frontend/src/store/pinia-modules/bookmark.ts b/frontend/src/store/pinia-modules/bookmark.ts
index 8bdf848af6..32197608d8 100644
--- a/frontend/src/store/pinia-modules/bookmark.ts
+++ b/frontend/src/store/pinia-modules/bookmark.ts
@@ -8,7 +8,7 @@ import {
ResourceObject,
unknown,
} from "../../types";
-import { getPrincipalFromIncludedList } from "@/store/modules/principal";
+import { getPrincipalFromIncludedList } from "./principal";
function convert(
bookmark: ResourceObject,
diff --git a/frontend/src/store/pinia-modules/deployment.ts b/frontend/src/store/pinia-modules/deployment.ts
index 866acdc24c..d563bd7f44 100644
--- a/frontend/src/store/pinia-modules/deployment.ts
+++ b/frontend/src/store/pinia-modules/deployment.ts
@@ -11,7 +11,7 @@ import {
UNKNOWN_ID,
DeploymentConfigPatch,
} from "@/types";
-import { getPrincipalFromIncludedList } from "../modules/principal";
+import { getPrincipalFromIncludedList } from "./principal";
function convert(
deployment: ResourceObject,
diff --git a/frontend/src/store/pinia-modules/environment.ts b/frontend/src/store/pinia-modules/environment.ts
index 2da638eb9f..9bbcea4e7f 100644
--- a/frontend/src/store/pinia-modules/environment.ts
+++ b/frontend/src/store/pinia-modules/environment.ts
@@ -10,9 +10,9 @@ import {
ResourceObject,
RowStatus,
unknown,
-} from "../../types";
+} from "@/types";
import { usePolicyStore } from "./policy";
-import { getPrincipalFromIncludedList } from "../modules/principal";
+import { getPrincipalFromIncludedList } from "./principal";
import { defineStore } from "pinia";
import { computed } from "vue";
diff --git a/frontend/src/store/pinia-modules/index.ts b/frontend/src/store/pinia-modules/index.ts
index abd0a4cfb4..5445a916f3 100644
--- a/frontend/src/store/pinia-modules/index.ts
+++ b/frontend/src/store/pinia-modules/index.ts
@@ -1,5 +1,6 @@
export * from "./actuator";
export * from "./anomaly";
+export * from "./auth";
export * from "./backup";
export * from "./bookmark";
export * from "./command";
@@ -8,9 +9,11 @@ export * from "./deployment";
export * from "./environment";
export * from "./issueSubscriber";
export * from "./label";
+export * from "./member";
export * from "./notification";
export * from "./oauth";
export * from "./policy";
+export * from "./principal";
export * from "./router";
export * from "./setting";
export * from "./subscription";
diff --git a/frontend/src/store/pinia-modules/issueSubscriber.ts b/frontend/src/store/pinia-modules/issueSubscriber.ts
index f346d84cc1..c5dc726319 100644
--- a/frontend/src/store/pinia-modules/issueSubscriber.ts
+++ b/frontend/src/store/pinia-modules/issueSubscriber.ts
@@ -7,7 +7,7 @@ import {
ResourceObject,
IssueId,
} from "../../types";
-import { getPrincipalFromIncludedList } from "@/store/modules/principal";
+import { getPrincipalFromIncludedList } from "./principal";
function convert(
issueSubscriber: ResourceObject,
diff --git a/frontend/src/store/pinia-modules/member.ts b/frontend/src/store/pinia-modules/member.ts
new file mode 100644
index 0000000000..88726cc4f4
--- /dev/null
+++ b/frontend/src/store/pinia-modules/member.ts
@@ -0,0 +1,153 @@
+import axios from "axios";
+import { defineStore, storeToRefs } from "pinia";
+import { watchEffect } from "vue";
+import {
+ Member,
+ MemberId,
+ MemberCreate,
+ MemberPatch,
+ MemberState,
+ ResourceObject,
+ PrincipalId,
+ unknown,
+ empty,
+ EMPTY_ID,
+ RoleType,
+} from "@/types";
+import { getPrincipalFromIncludedList } from "./principal";
+
+function convert(
+ member: ResourceObject,
+ includedList: ResourceObject[]
+): Member {
+ const principal = getPrincipalFromIncludedList(
+ member.relationships!.principal.data,
+ includedList
+ );
+ principal.role = member.attributes.role as RoleType;
+
+ return {
+ ...(member.attributes as Omit<
+ Member,
+ "id" | "principal" | "creator" | "updater"
+ >),
+ id: parseInt(member.id),
+ creator: getPrincipalFromIncludedList(
+ member.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ member.relationships!.updater.data,
+ includedList
+ ),
+ principal: principal,
+ };
+}
+
+export const useMemberStore = defineStore("member", {
+ state: (): MemberState => ({
+ memberList: [],
+ }),
+ actions: {
+ memberByPrincipalId(id: PrincipalId): Member {
+ if (id == EMPTY_ID) {
+ return empty("MEMBER") as Member;
+ }
+
+ return (
+ this.memberList.find((item) => item.principal.id == id) ||
+ (unknown("MEMBER") as Member)
+ );
+ },
+ memberByEmail(email: string): Member {
+ return (
+ this.memberList.find((item) => item.principal.email == email) ||
+ (unknown("MEMBER") as Member)
+ );
+ },
+ setMemberList(memberList: Member[]) {
+ this.memberList = memberList;
+ },
+ appendMember(newMember: Member) {
+ this.memberList.push(newMember);
+ },
+ replaceMemberInList(updatedMember: Member) {
+ const i = this.memberList.findIndex(
+ (item: Member) => item.id == updatedMember.id
+ );
+ if (i !== -1) {
+ this.memberList[i] = updatedMember;
+ }
+ },
+ async fetchMemberList() {
+ const data = (await axios.get(`/api/member`)).data;
+ const memberList: Member[] = data.data.map((member: ResourceObject) => {
+ return convert(member, data.included);
+ });
+
+ // sort the member list
+ memberList.sort((a: Member, b: Member) => {
+ if (a.createdTs === b.createdTs) {
+ return a.id - b.id;
+ }
+ return a.createdTs - b.createdTs;
+ });
+
+ this.setMemberList(memberList);
+ return memberList;
+ },
+ // Returns existing member if the principalId has already been created.
+ async createdMember(newMember: MemberCreate) {
+ const data = (
+ await axios.post(`/api/member`, {
+ data: {
+ type: "MemberCreate",
+ attributes: newMember,
+ },
+ })
+ ).data;
+ const createdMember = convert(data.data, data.included);
+
+ this.appendMember(createdMember);
+
+ return createdMember;
+ },
+ async patchMember({
+ id,
+ memberPatch,
+ }: {
+ id: MemberId;
+ memberPatch: MemberPatch;
+ }) {
+ const data = (
+ await axios.patch(`/api/member/${id}`, {
+ data: {
+ type: "memberPatch",
+ attributes: memberPatch,
+ },
+ })
+ ).data;
+ const updatedMember = convert(data.data, data.included);
+
+ this.replaceMemberInList(updatedMember);
+
+ return updatedMember;
+ },
+ async deleteMemberById(id: MemberId) {
+ await axios.delete(`/api/member/${id}`);
+
+ const newList = this.memberList.filter((item: Member) => {
+ return item.id != id;
+ });
+
+ this.setMemberList(newList);
+ },
+ },
+});
+
+export const useMemberList = () => {
+ const store = useMemberStore();
+ watchEffect(() => store.fetchMemberList());
+
+ return storeToRefs(store).memberList;
+};
diff --git a/frontend/src/store/pinia-modules/policy.ts b/frontend/src/store/pinia-modules/policy.ts
index 6ea62aa3a3..41a2235936 100644
--- a/frontend/src/store/pinia-modules/policy.ts
+++ b/frontend/src/store/pinia-modules/policy.ts
@@ -8,9 +8,9 @@ import {
unknown,
} from "@/types";
import { Policy, PolicyType, PolicyUpsert } from "@/types/policy";
-import { getPrincipalFromIncludedList } from "../modules/principal";
-import { defineStore } from "pinia";
+import { getPrincipalFromIncludedList } from "./principal";
import { useEnvironmentStore } from "./environment";
+import { defineStore } from "pinia";
function convert(
policy: ResourceObject,
diff --git a/frontend/src/store/pinia-modules/principal.ts b/frontend/src/store/pinia-modules/principal.ts
new file mode 100644
index 0000000000..91aef36123
--- /dev/null
+++ b/frontend/src/store/pinia-modules/principal.ts
@@ -0,0 +1,155 @@
+import axios from "axios";
+import {
+ PrincipalId,
+ Principal,
+ PrincipalCreate,
+ PrincipalPatch,
+ PrincipalState,
+ ResourceObject,
+ unknown,
+ empty,
+ EMPTY_ID,
+ PrincipalType,
+ ResourceIdentifier,
+ RoleType,
+} from "@/types";
+import { randomString } from "@/utils";
+import { defineStore } from "pinia";
+import { useAuthStore } from "./auth";
+
+function convert(principal: ResourceObject): Principal {
+ return {
+ id: parseInt(principal.id),
+ creatorId: principal.attributes.creatorId as PrincipalId,
+ createdTs: principal.attributes.createdTs as number,
+ updaterId: principal.attributes.updaterId as PrincipalId,
+ updatedTs: principal.attributes.updatedTs as number,
+ type: principal.attributes.type as PrincipalType,
+ name: principal.attributes.name as string,
+ email: principal.attributes.email as string,
+ role: principal.attributes.role as RoleType,
+ };
+}
+
+export function getPrincipalFromIncludedList(
+ data:
+ | ResourceIdentifier<ResourceObject>
+ | ResourceIdentifier<ResourceObject>[]
+ | undefined,
+ includedList: ResourceObject[]
+): Principal {
+ if (data == null) {
+ return empty("PRINCIPAL") as Principal;
+ }
+ for (const item of includedList || []) {
+ if (item.type != "principal") {
+ continue;
+ }
+ if (item.id == (data as ResourceIdentifier).id) {
+ return convert(item);
+ }
+ }
+ return empty("PRINCIPAL") as Principal;
+}
+
+export const usePrincipalStore = defineStore("principal", {
+ state: (): PrincipalState => ({
+ principalList: [],
+ }),
+ actions: {
+ convert(principal: ResourceObject): Principal {
+ return convert(principal);
+ },
+ principalById(principalId: PrincipalId): Principal {
+ if (principalId == EMPTY_ID) {
+ return empty("PRINCIPAL") as Principal;
+ }
+
+ return (
+ this.principalList.find((item) => item.id == principalId) ||
+ (unknown("PRINCIPAL") as Principal)
+ );
+ },
+ setPrincipalList(principalList: Principal[]) {
+ this.principalList = principalList;
+ },
+ appendPrincipal(newPrincipal: Principal) {
+ this.principalList.push(newPrincipal);
+ },
+ upsertPrincipalInList(updatedPrincipal: Principal) {
+ const i = this.principalList.findIndex(
+ (item: Principal) => item.id == updatedPrincipal.id
+ );
+ if (i == -1) {
+ this.principalList.push(updatedPrincipal);
+ } else {
+ this.principalList[i] = updatedPrincipal;
+ }
+ },
+ async fetchPrincipalList() {
+ const userList: ResourceObject[] = (await axios.get(`/api/principal`))
+ .data.data;
+ const principalList = userList.map((user) => {
+ return convert(user);
+ });
+
+ this.setPrincipalList(principalList);
+
+ return principalList;
+ },
+ async fetchPrincipalById(principalId: PrincipalId) {
+ const principal = convert(
+ (await axios.get(`/api/principal/${principalId}`)).data.data
+ );
+
+ this.upsertPrincipalInList(principal);
+
+ return principal;
+ },
+ // Returns existing user if already created.
+ async createPrincipal(newPrincipal: PrincipalCreate) {
+ const createdPrincipal = convert(
+ (
+ await axios.post(`/api/principal`, {
+ data: {
+ type: "PrincipalCreate",
+ attributes: {
+ name: newPrincipal.name,
+ email: newPrincipal.email,
+ password: randomString(),
+ },
+ },
+ })
+ ).data.data
+ );
+
+ this.appendPrincipal(createdPrincipal);
+
+ return createdPrincipal;
+ },
+ async patchPrincipal({
+ principalId,
+ principalPatch,
+ }: {
+ principalId: PrincipalId;
+ principalPatch: PrincipalPatch;
+ }) {
+ const updatedPrincipal = convert(
+ (
+ await axios.patch(`/api/principal/${principalId}`, {
+ data: {
+ type: "principalPatch",
+ attributes: principalPatch,
+ },
+ })
+ ).data.data
+ );
+
+ this.upsertPrincipalInList(updatedPrincipal);
+
+ useAuthStore().refreshUserIfNeeded(updatedPrincipal.id);
+
+ return updatedPrincipal;
+ },
+ },
+});
diff --git a/frontend/src/store/pinia-modules/setting.ts b/frontend/src/store/pinia-modules/setting.ts
index bd2c4a2da7..5980b9886f 100644
--- a/frontend/src/store/pinia-modules/setting.ts
+++ b/frontend/src/store/pinia-modules/setting.ts
@@ -2,7 +2,7 @@ import axios from "axios";
import { defineStore } from "pinia";
import { ResourceObject, SettingState } from "@/types";
import { Setting, SettingName } from "@/types/setting";
-import { getPrincipalFromIncludedList } from "../modules/principal";
+import { getPrincipalFromIncludedList } from "./principal";
function convert(
setting: ResourceObject,
diff --git a/frontend/src/utils/activity.ts b/frontend/src/utils/activity.ts
index aabd5f70ef..172f4fbef1 100644
--- a/frontend/src/utils/activity.ts
+++ b/frontend/src/utils/activity.ts
@@ -1,3 +1,4 @@
+import { usePrincipalStore } from "@/store";
import { Store } from "vuex";
import { IssueBuiltinFieldId } from "../plugins";
import {
@@ -21,6 +22,7 @@ export function issueActivityActionSentence(
case "bb.issue.comment.create":
return ["activity.sentence.commented", {}];
case "bb.issue.field.update": {
+ const principalStore = usePrincipalStore();
const update = activity.payload as ActivityIssueFieldUpdatePayload;
const name = "Unknown Field";
@@ -30,13 +32,9 @@ export function issueActivityActionSentence(
switch (update.fieldId) {
case IssueBuiltinFieldId.ASSIGNEE: {
if (update.oldValue && update.newValue) {
- const oldName = store.getters["principal/principalById"](
- update.oldValue
- ).name;
+ const oldName = principalStore.principalById(+update.oldValue).name;
- const newName = store.getters["principal/principalById"](
- update.newValue
- ).name;
+ const newName = principalStore.principalById(+update.newValue).name;
return [
"activity.sentence.reassigned-issue",
{
@@ -45,9 +43,7 @@ export function issueActivityActionSentence(
},
];
} else if (!update.oldValue && update.newValue) {
- const newName = store.getters["principal/principalById"](
- update.newValue
- ).name;
+ const newName = principalStore.principalById(+update.newValue).name;
return [
"activity.sentence.assigned-issue",
{
@@ -55,9 +51,7 @@ export function issueActivityActionSentence(
},
];
} else if (update.oldValue && !update.newValue) {
- const oldName = store.getters["principal/principalById"](
- update.oldValue
- ).name;
+ const oldName = principalStore.principalById(+update.oldValue).name;
return [
"activity.sentence.unassigned-issue",
{
diff --git a/frontend/src/views/AnomalyCenterDashboard.vue b/frontend/src/views/AnomalyCenterDashboard.vue
index e8f719b316..703d888024 100644
--- a/frontend/src/views/AnomalyCenterDashboard.vue
+++ b/frontend/src/views/AnomalyCenterDashboard.vue
@@ -141,7 +141,7 @@ import {
} from "../utils";
import { BBTabFilterItem, BBTableSectionDataSource } from "../bbkit/types";
import { cloneDeep } from "lodash-es";
-import { featureToRef, useEnvironmentList } from "@/store";
+import { featureToRef, useCurrentUser, useEnvironmentList } from "@/store";
const DATABASE_TAB = 0;
const INSTANCE_TAB = 1;
@@ -165,7 +165,7 @@ export default defineComponent({
const store = useStore();
const { t } = useI18n();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const state = reactive<LocalState>({
selectedIndex: isDBAOrOwner(currentUser.value.role)
diff --git a/frontend/src/views/Archive.vue b/frontend/src/views/Archive.vue
index 175f075ae1..fdea9ffb59 100644
--- a/frontend/src/views/Archive.vue
+++ b/frontend/src/views/Archive.vue
@@ -39,28 +39,20 @@
</template>
<script lang="ts">
-import {
- computed,
- ComputedRef,
- defineComponent,
- reactive,
- watchEffect,
-} from "vue";
+import { computed, defineComponent, reactive, watchEffect } from "vue";
import { useStore } from "vuex";
import EnvironmentTable from "../components/EnvironmentTable.vue";
import InstanceTable from "../components/InstanceTable.vue";
import ProjectTable from "../components/ProjectTable.vue";
-import {
- Environment,
- Instance,
- Principal,
- Project,
- UNKNOWN_ID,
-} from "../types";
+import { Environment, Instance, Project, UNKNOWN_ID } from "../types";
import { isDBAOrOwner } from "../utils";
import { BBTabFilterItem } from "../bbkit/types";
import { useI18n } from "vue-i18n";
-import { useEnvironmentList, useEnvironmentStore } from "@/store";
+import {
+ useCurrentUser,
+ useEnvironmentList,
+ useEnvironmentStore,
+} from "@/store";
const PROJECT_TAB = 0;
const INSTANCE_TAB = 1;
@@ -82,9 +74,7 @@ export default defineComponent({
searchText: "",
});
- const currentUser: ComputedRef<Principal> = computed(() =>
- store.getters["auth/currentUser"]()
- );
+ const currentUser = useCurrentUser();
const store = useStore();
diff --git a/frontend/src/views/DashboardHeader.vue b/frontend/src/views/DashboardHeader.vue
index c5f84e67ba..300518f810 100644
--- a/frontend/src/views/DashboardHeader.vue
+++ b/frontend/src/views/DashboardHeader.vue
@@ -199,7 +199,12 @@ import { InboxSummary, UNKNOWN_ID } from "../types";
import { brandingLogoSettingName } from "../types/setting";
import { isDBAOrOwner, isDev } from "../utils";
import { useLanguage } from "../composables/useLanguage";
-import { useSettingStore, useSubscriptionStore } from "@/store";
+import {
+ useCurrentUser,
+ useAuthStore,
+ useSettingStore,
+ useSubscriptionStore,
+} from "@/store";
import { storeToRefs } from "pinia";
interface LocalState {
@@ -212,6 +217,7 @@ export default defineComponent({
setup() {
const { t, availableLocales } = useI18n();
const store = useStore();
+ const authStore = useAuthStore();
const settingStore = useSettingStore();
const subscriptionStore = useSubscriptionStore();
const router = useRouter();
@@ -221,7 +227,7 @@ export default defineComponent({
showMobileMenu: false,
});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const { currentPlan } = storeToRefs(subscriptionStore);
@@ -260,7 +266,7 @@ export default defineComponent({
});
const switchToOwner = () => {
- store.dispatch("auth/login", {
+ authStore.login({
authProvider: "BYTEBASE",
payload: {
@@ -270,7 +276,7 @@ export default defineComponent({
};
const switchToDBA = () => {
- store.dispatch("auth/login", {
+ authStore.login({
authProvider: "BYTEBASE",
payload: {
@@ -280,7 +286,7 @@ export default defineComponent({
};
const switchToDeveloper = () => {
- store.dispatch("auth/login", {
+ authStore.login({
authProvider: "BYTEBASE",
payload: {
diff --git a/frontend/src/views/DataSourceDetail.vue b/frontend/src/views/DataSourceDetail.vue
index 3a648307d6..49eb9029e4 100644
--- a/frontend/src/views/DataSourceDetail.vue
+++ b/frontend/src/views/DataSourceDetail.vue
@@ -161,9 +161,9 @@ import isEqual from "lodash-es/isEqual";
import DataSourceConnectionPanel from "../components/DataSourceConnectionPanel.vue";
import DataSourceMemberTable from "../components/DataSourceMemberTable.vue";
import { idFromSlug, isDBAOrOwner } from "../utils";
-import { DataSource, DataSourcePatch, Principal } from "../types";
+import { DataSource, DataSourcePatch } from "../types";
import { useI18n } from "vue-i18n";
-import { pushNotification } from "@/store";
+import { pushNotification, useCurrentUser } from "@/store";
interface LocalState {
editing: boolean;
@@ -199,9 +199,7 @@ export default defineComponent({
showPassword: false,
});
- const currentUser = computed(
- (): Principal => store.getters["auth/currentUser"]()
- );
+ const currentUser = useCurrentUser();
const dataSource = computed((): DataSource => {
return store.getters["dataSource/dataSourceById"](dataSourceId);
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index 32b0c754e5..22e2d23c8c 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -49,6 +49,7 @@ import { Environment, Database, UNKNOWN_ID } from "../types";
import { sortDatabaseList } from "../utils";
import { cloneDeep } from "lodash-es";
import {
+ useCurrentUser,
useEnvironmentList,
useEnvironmentStore,
useUIStateStore,
@@ -85,7 +86,7 @@ export default defineComponent({
showGuide: false,
});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const environmentList = useEnvironmentList(["NORMAL"]);
diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vue
index 25d508a8d4..6e8ba7e21e 100644
--- a/frontend/src/views/DatabaseDetail.vue
+++ b/frontend/src/views/DatabaseDetail.vue
@@ -305,7 +305,7 @@ import {
} from "../types";
import { BBTabFilterItem } from "../bbkit/types";
import { useI18n } from "vue-i18n";
-import { pushNotification } from "@/store";
+import { pushNotification, useCurrentUser } from "@/store";
const OVERVIEW_TAB = 0;
const MIGRATION_HISTORY_TAB = 1;
@@ -358,7 +358,7 @@ export default defineComponent({
selectedIndex: OVERVIEW_TAB,
});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const database = computed((): Database => {
return store.getters["database/databaseById"](
diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue
index 35a75ebb98..94b9e03cca 100644
--- a/frontend/src/views/Home.vue
+++ b/frontend/src/views/Home.vue
@@ -48,21 +48,14 @@
</template>
<script lang="ts">
-import {
- watchEffect,
- computed,
- onMounted,
- reactive,
- ref,
- defineComponent,
-} from "vue";
+import { watchEffect, onMounted, reactive, ref, defineComponent } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";
import { IssueTable } from "../components/Issue";
import { activeEnvironment, activeTask } from "../utils";
import { Environment, Issue, TaskStatus, UNKNOWN_ID } from "../types";
-import { useEnvironmentStore } from "@/store";
+import { useCurrentUser, useEnvironmentStore } from "@/store";
// Show at most 10 recently closed issues
const MAX_CLOSED_ISSUE_COUNT = 10;
@@ -101,7 +94,7 @@ export default defineComponent({
: undefined,
});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
onMounted(() => {
// Focus on the internal search field when mounted
@@ -129,7 +122,7 @@ export default defineComponent({
issue.subscriberList &&
issue.subscriberList
.map((subscriber) => subscriber.id)
- .includes(currentUser.value)
+ .includes(currentUser.value.id)
) {
state.subscribeList.push(issue);
}
diff --git a/frontend/src/views/Inbox.vue b/frontend/src/views/Inbox.vue
index 4ef1a20100..c54f4316a2 100644
--- a/frontend/src/views/Inbox.vue
+++ b/frontend/src/views/Inbox.vue
@@ -34,11 +34,12 @@
</template>
<script lang="ts">
-import { computed, reactive, watchEffect } from "vue";
+import { reactive, watchEffect } from "vue";
import { useStore } from "vuex";
import InboxList from "../components/InboxList.vue";
import { Inbox, UNKNOWN_ID } from "../types";
import { useRouter } from "vue-router";
+import { useCurrentUser } from "@/store";
// We alway fetch all "UNREAD" items. But for "READ" items, by default, we only fetch the most recent 7 days.
// And each time clicking "View older" will extend 7 days further.
@@ -65,7 +66,7 @@ export default {
Math.ceil(Date.now() / 1000) - READ_INBOX_DURATION_STEP,
});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const prepareInboxList = () => {
// It will also be called when user logout
diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vue
index 11e132a0cb..86b0b02a2c 100644
--- a/frontend/src/views/InstanceDetail.vue
+++ b/frontend/src/views/InstanceDetail.vue
@@ -156,7 +156,12 @@ import {
} from "../types";
import { BBTabFilterItem } from "../bbkit/types";
import { useI18n } from "vue-i18n";
-import { featureToRef, pushNotification, useSubscriptionStore } from "@/store";
+import {
+ featureToRef,
+ pushNotification,
+ useCurrentUser,
+ useSubscriptionStore,
+} from "@/store";
const DATABASE_TAB = 0;
const USER_TAB = 1;
@@ -182,7 +187,7 @@ const store = useStore();
const subscriptionStore = useSubscriptionStore();
const { t } = useI18n();
-const currentUser = computed(() => store.getters["auth/currentUser"]());
+const currentUser = useCurrentUser();
const state = reactive<LocalState>({
selectedIndex: DATABASE_TAB,
diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vue
index 5272cc6668..88484b2584 100644
--- a/frontend/src/views/IssueDashboard.vue
+++ b/frontend/src/views/IssueDashboard.vue
@@ -57,7 +57,7 @@ import {
import { activeEnvironment, projectSlug } from "../utils";
import { BBTableSectionDataSource } from "../bbkit/types";
import { useI18n } from "vue-i18n";
-import { useEnvironmentStore } from "@/store";
+import { useCurrentUser, useEnvironmentStore } from "@/store";
interface LocalState {
showOpen: boolean;
@@ -80,7 +80,7 @@ export default defineComponent({
const store = useStore();
const router = useRouter();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const statusList: string[] = router.currentRoute.value.query.status
? (router.currentRoute.value.query.status as string).split(",")
diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vue
index 07290ab442..68f589c669 100644
--- a/frontend/src/views/IssueDetail.vue
+++ b/frontend/src/views/IssueDetail.vue
@@ -54,7 +54,12 @@ import {
TemplateType,
} from "../plugins";
import { NSpin } from "naive-ui";
-import { hasFeature, pushNotification, useActuatorStore } from "@/store";
+import {
+ hasFeature,
+ pushNotification,
+ useActuatorStore,
+ useCurrentUser,
+} from "@/store";
interface LocalState {
// Needs to maintain this state and set it to false manually after creating the issue.
@@ -89,7 +94,7 @@ export default defineComponent({
const store = useStore();
const route = useRoute();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
let newIssueTemplate = ref<IssueTemplate>(defaultTemplate());
diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vue
index b050ca2c8c..756e5b2630 100644
--- a/frontend/src/views/ProfileDashboard.vue
+++ b/frontend/src/views/ProfileDashboard.vue
@@ -173,14 +173,13 @@ import {
ref,
defineComponent,
} from "vue";
-import { useStore } from "vuex";
import cloneDeep from "lodash-es/cloneDeep";
import isEmpty from "lodash-es/isEmpty";
import isEqual from "lodash-es/isEqual";
import PrincipalAvatar from "../components/PrincipalAvatar.vue";
-import { Principal, PrincipalPatch } from "../types";
+import { PrincipalPatch } from "../types";
import { isOwner } from "../utils";
-import { featureToRef } from "@/store";
+import { featureToRef, useCurrentUser, usePrincipalStore } from "@/store";
interface LocalState {
editing: boolean;
@@ -200,7 +199,7 @@ export default defineComponent({
setup(props) {
const editNameTextField = ref();
- const store = useStore();
+ const principalStore = usePrincipalStore();
const state = reactive<LocalState>({
editing: false,
@@ -226,17 +225,13 @@ export default defineComponent({
document.removeEventListener("keydown", keyboardHandler);
});
- const currentUser = computed(
- (): Principal => store.getters["auth/currentUser"]()
- );
+ const currentUser = useCurrentUser();
const hasRBACFeature = featureToRef("bb.feature.rbac");
const principal = computed(() => {
if (props.principalId) {
- return store.getters["principal/principalById"](
- parseInt(props.principalId)
- );
+ return principalStore.principalById(parseInt(props.principalId));
}
return currentUser.value;
});
@@ -285,10 +280,10 @@ export default defineComponent({
};
const saveEdit = () => {
- store
- .dispatch("principal/patchPrincipal", {
+ principalStore
+ .patchPrincipal({
principalId: principal.value.id,
- principalPatch: state.editingPrincipal,
+ principalPatch: state.editingPrincipal!,
})
.then(() => {
state.editingPrincipal = undefined;
diff --git a/frontend/src/views/ProjectDashboard.vue b/frontend/src/views/ProjectDashboard.vue
index e59d7ccf2b..764ede1080 100644
--- a/frontend/src/views/ProjectDashboard.vue
+++ b/frontend/src/views/ProjectDashboard.vue
@@ -28,15 +28,8 @@
</template>
<script lang="ts">
-import { useUIStateStore } from "@/store";
-import {
- watchEffect,
- computed,
- onMounted,
- reactive,
- ref,
- defineComponent,
-} from "vue";
+import { useCurrentUser, useUIStateStore } from "@/store";
+import { watchEffect, onMounted, reactive, ref, defineComponent } from "vue";
import { useStore } from "vuex";
import ProjectTable from "../components/ProjectTable.vue";
import { Project, UNKNOWN_ID } from "../types";
@@ -64,7 +57,7 @@ export default defineComponent({
showGuide: false,
});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
onMounted(() => {
// Focus on the internal search field when mounted
diff --git a/frontend/src/views/SettingSidebar.vue b/frontend/src/views/SettingSidebar.vue
index 4524f19537..9eebe0d227 100644
--- a/frontend/src/views/SettingSidebar.vue
+++ b/frontend/src/views/SettingSidebar.vue
@@ -89,10 +89,9 @@
<script lang="ts">
import { computed, defineComponent, reactive } from "vue";
-import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { isOwner, isDev } from "../utils";
-import { useRouterStore } from "@/store";
+import { useCurrentUser, useRouterStore } from "@/store";
interface LocalState {
collapseState: boolean;
@@ -107,7 +106,6 @@ export default defineComponent({
},
},
setup() {
- const store = useStore();
const routerStore = useRouterStore();
const router = useRouter();
@@ -115,7 +113,7 @@ export default defineComponent({
collapseState: true,
});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const showOwnerItem = computed((): boolean => {
return isOwner(currentUser.value.role);
diff --git a/frontend/src/views/SettingWorkspaceGeneral.vue b/frontend/src/views/SettingWorkspaceGeneral.vue
index deb395c1c7..3dcb1e296d 100644
--- a/frontend/src/views/SettingWorkspaceGeneral.vue
+++ b/frontend/src/views/SettingWorkspaceGeneral.vue
@@ -94,11 +94,15 @@
<script lang="ts" setup>
import { computed, reactive } from "vue";
-import { useStore } from "vuex";
import { isOwner } from "../utils";
import { brandingLogoSettingName } from "../types/setting";
import { useI18n } from "vue-i18n";
-import { featureToRef, pushNotification, useSettingStore } from "@/store";
+import {
+ featureToRef,
+ pushNotification,
+ useCurrentUser,
+ useSettingStore,
+} from "@/store";
interface LocalState {
displayName?: string;
@@ -120,7 +124,6 @@ const convertFileToBase64 = (file: File) =>
reader.onerror = (error) => reject(error);
});
-const store = useStore();
const settingStore = useSettingStore();
const { t } = useI18n();
@@ -139,7 +142,7 @@ settingStore.fetchSetting().then(() => {
state.logoUrl = brandingLogoSetting.value;
});
-const currentUser = computed(() => store.getters["auth/currentUser"]());
+const currentUser = useCurrentUser();
const allowEdit = computed((): boolean => {
return isOwner(currentUser.value.role);
diff --git a/frontend/src/views/SettingWorkspaceLabel.vue b/frontend/src/views/SettingWorkspaceLabel.vue
index 30d3aac263..36c878e4cf 100644
--- a/frontend/src/views/SettingWorkspaceLabel.vue
+++ b/frontend/src/views/SettingWorkspaceLabel.vue
@@ -66,14 +66,13 @@
<script lang="ts">
import { computed, defineComponent, watchEffect } from "vue";
-import { useStore } from "vuex";
import { isDBAOrOwner, hidePrefix } from "../utils";
-import { Principal, Label, LabelPatch } from "../types";
+import { Label, LabelPatch } from "../types";
import { BBTableColumn } from "../bbkit/types";
import { BBTable, BBTableCell } from "../bbkit";
import { useI18n } from "vue-i18n";
import AddLabelValue from "../components/AddLabelValue.vue";
-import { useLabelStore } from "@/store";
+import { useCurrentUser, useLabelStore } from "@/store";
import { storeToRefs } from "pinia";
export default defineComponent({
@@ -85,11 +84,8 @@ export default defineComponent({
},
setup() {
const { t } = useI18n();
- const store = useStore();
const labelStore = useLabelStore();
- const currentUser = computed(
- () => store.getters["auth/currentUser"]() as Principal
- );
+ const currentUser = useCurrentUser();
const prepareLabelList = () => {
labelStore.fetchLabelList();
diff --git a/frontend/src/views/SettingWorkspaceMember.vue b/frontend/src/views/SettingWorkspaceMember.vue
index 67c694dbfa..757b663d9e 100644
--- a/frontend/src/views/SettingWorkspaceMember.vue
+++ b/frontend/src/views/SettingWorkspaceMember.vue
@@ -31,37 +31,31 @@
</template>
<script lang="ts">
-import { computed, defineComponent, watchEffect } from "vue";
-import { useStore } from "vuex";
+import { computed, defineComponent } from "vue";
import MemberAddOrInvite from "../components/MemberAddOrInvite.vue";
import MemberTable from "../components/MemberTable.vue";
import { isOwner } from "../utils";
import { Member } from "../types";
-import { featureToRef } from "@/store";
+import { featureToRef, useCurrentUser, useMemberList } from "@/store";
export default defineComponent({
name: "SettingWorkspaceMember",
components: { MemberAddOrInvite, MemberTable },
setup() {
- const store = useStore();
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const hasRBACFeature = featureToRef("bb.feature.rbac");
- const prepareMemberList = () => {
- store.dispatch("member/fetchMemberList");
- };
-
- watchEffect(prepareMemberList);
+ const memberList = useMemberList();
const activeMemberList = computed(() => {
- return store.getters["member/memberList"]().filter(
+ return memberList.value.filter(
(member: Member) => member.rowStatus == "NORMAL"
);
});
const inactiveMemberList = computed(() => {
- return store.getters["member/memberList"]().filter(
+ return memberList.value.filter(
(member: Member) => member.rowStatus == "ARCHIVED"
);
});
diff --git a/frontend/src/views/SqlEditor/EditorHeader.vue b/frontend/src/views/SqlEditor/EditorHeader.vue
index d21bd186d9..25e75e6b5f 100644
--- a/frontend/src/views/SqlEditor/EditorHeader.vue
+++ b/frontend/src/views/SqlEditor/EditorHeader.vue
@@ -102,7 +102,7 @@ import { useStore } from "vuex";
import ProfileDropdown from "@/components/ProfileDropdown.vue";
import { InboxSummary, UNKNOWN_ID } from "@/types";
import { isDBAOrOwner, isDev } from "@/utils";
-import { hasFeature, useSubscriptionStore } from "@/store";
+import { hasFeature, useCurrentUser, useSubscriptionStore } from "@/store";
import { storeToRefs } from "pinia";
interface LocalState {
@@ -122,7 +122,7 @@ export default defineComponent({
showMobileMenu: false,
});
- const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const currentUser = useCurrentUser();
const { currentPlan } = storeToRefs(subscriptionStore);
diff --git a/frontend/src/views/auth/Activate.vue b/frontend/src/views/auth/Activate.vue
index 7bbc4a21ad..a422069c5f 100644
--- a/frontend/src/views/auth/Activate.vue
+++ b/frontend/src/views/auth/Activate.vue
@@ -87,10 +87,10 @@
</template>
<script lang="ts">
-import { reactive } from "vue";
-import { useStore } from "vuex";
+import { defineComponent, reactive } from "vue";
import { useRouter } from "vue-router";
import { ActivateInfo, RoleType } from "../../types";
+import { useAuthStore } from "@/store";
interface LocalState {
email: string;
@@ -99,10 +99,9 @@ interface LocalState {
role: RoleType;
}
-export default {
+export default defineComponent({
name: "Activate",
setup() {
- const store = useStore();
const router = useRouter();
const token = router.currentRoute.value.query.token as string;
@@ -121,9 +120,11 @@ export default {
name: state.name,
token: token,
};
- store.dispatch("auth/activate", activateInfo).then(() => {
- router.push("/");
- });
+ useAuthStore()
+ .activate(activateInfo)
+ .then(() => {
+ router.push("/");
+ });
};
return {
@@ -131,5 +132,5 @@ export default {
tryActivate,
};
},
-};
+});
</script>
diff --git a/frontend/src/views/auth/Signin.vue b/frontend/src/views/auth/Signin.vue
index db0fa3ccb6..dff4144f20 100644
--- a/frontend/src/views/auth/Signin.vue
+++ b/frontend/src/views/auth/Signin.vue
@@ -165,7 +165,6 @@ import {
onUnmounted,
reactive,
} from "vue";
-import { useStore } from "vuex";
import { useRouter } from "vue-router";
import {
AuthProvider,
@@ -174,11 +173,10 @@ import {
LoginInfo,
OAuthWindowEventPayload,
openWindowForOAuth,
- redirectUrl,
} from "../../types";
import { isDev, isValidEmail } from "../../utils";
import AuthFooter from "./AuthFooter.vue";
-import { featureToRef, useActuatorStore } from "@/store";
+import { featureToRef, useActuatorStore, useAuthStore } from "@/store";
import { storeToRefs } from "pinia";
interface LocalState {
@@ -191,8 +189,8 @@ export default defineComponent({
name: "SigninPage",
components: { AuthFooter },
setup() {
- const store = useStore();
const actuatorStore = useActuatorStore();
+ const authStore = useAuthStore();
const router = useRouter();
const state = reactive<LocalState>({
@@ -212,7 +210,7 @@ export default defineComponent({
router.push({ name: "auth.signup", replace: true });
}
- store.dispatch("auth/fetchProviderList");
+ authStore.fetchProviderList();
window.addEventListener("bb.oauth.signin", eventListener, false);
});
@@ -225,9 +223,7 @@ export default defineComponent({
return isValidEmail(state.email) && state.password;
});
- const authProviderList = computed(() => {
- return store.getters["auth/authProviderList"]();
- });
+ const { authProviderList } = storeToRefs(authStore);
const eventListener = (event: Event) => {
const payload = (event as CustomEvent).detail as OAuthWindowEventPayload;
@@ -239,8 +235,8 @@ export default defineComponent({
name: state.activeAuthProvider.name,
code: payload.code,
};
- store
- .dispatch("auth/login", {
+ authStore
+ .login({
authProvider: "GITLAB_SELF_HOST",
payload: gitlabLoginInfo,
})
@@ -257,7 +253,7 @@ export default defineComponent({
password: state.password,
},
};
- store.dispatch("auth/login", loginInfo).then(() => {
+ authStore.login(loginInfo).then(() => {
router.push("/");
});
};
diff --git a/frontend/src/views/auth/Signup.vue b/frontend/src/views/auth/Signup.vue
index f93016f849..59face0071 100644
--- a/frontend/src/views/auth/Signup.vue
+++ b/frontend/src/views/auth/Signup.vue
@@ -151,12 +151,11 @@
<script lang="ts">
import { computed, defineComponent, onUnmounted, reactive } from "vue";
-import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { SignupInfo, TEXT_VALIDATION_DELAY } from "../../types";
import { isValidEmail } from "../../utils";
import AuthFooter from "./AuthFooter.vue";
-import { useActuatorStore } from "@/store";
+import { useActuatorStore, useAuthStore } from "@/store";
import { storeToRefs } from "pinia";
interface LocalState {
@@ -173,7 +172,6 @@ export default defineComponent({
name: "SignupPage",
components: { AuthFooter },
setup() {
- const store = useStore();
const actuatorStore = useActuatorStore();
const router = useRouter();
@@ -274,14 +272,16 @@ export default defineComponent({
password: state.password,
name: state.name,
};
- store.dispatch("auth/signup", signupInfo).then(async () => {
- // we need to update the server info after setting up the first admin account so that the splash screen
- // won't display the UI for registering the first admin account again.
- if (needAdminSetup.value) {
- await actuatorStore.fetchInfo();
- }
- router.push("/");
- });
+ useAuthStore()
+ .signup(signupInfo)
+ .then(async () => {
+ // we need to update the server info after setting up the first admin account so that the splash screen
+ // won't display the UI for registering the first admin account again.
+ if (needAdminSetup.value) {
+ await actuatorStore.fetchInfo();
+ }
+ router.push("/");
+ });
}
};