refactor(frontend): use auth service

This commit is contained in:
Steven
2023-12-01 09:15:02 +08:00
parent b944418257
commit e83d483454
19 changed files with 136 additions and 299 deletions

View File

@ -8,7 +8,7 @@ import * as api from "@/helpers/api";
import { absolutifyLink } from "@/helpers/utils";
import useLoading from "@/hooks/useLoading";
import useNavigateTo from "@/hooks/useNavigateTo";
import { useGlobalStore, useUserStore } from "@/store/module";
import { useGlobalStore } from "@/store/module";
import { useUserV1Store } from "@/store/v1";
import { useTranslate } from "@/utils/i18n";
@ -16,7 +16,6 @@ const SignIn = () => {
const t = useTranslate();
const navigateTo = useNavigateTo();
const globalStore = useGlobalStore();
const userStore = useUserStore();
const userV1Store = useUserV1Store();
const actionBtnLoadingState = useLoading(false);
const { appearance, locale, systemStatus } = globalStore.state;
@ -78,9 +77,7 @@ const SignIn = () => {
actionBtnLoadingState.setLoading();
const { data: user } = await api.signin(username, password, remember);
if (user) {
userStore.setCurrentUser(user);
await userStore.fetchCurrentUser();
await userV1Store.getOrFetchUserByUsername(user.username);
await userV1Store.fetchCurrentUser();
navigateTo("/");
} else {
toast.error(t("message.login-failed"));