新增用户注册功能

This commit is contained in:
Cheng Zhou
2025-12-22 21:19:48 +08:00
parent 03fddba406
commit 6ddf9901a0
33 changed files with 1389 additions and 138 deletions
+9 -2
View File
@@ -9,14 +9,16 @@ export const useAuthStore = defineStore("auth", () => {
const token = ref<string | null>(getToken());
const user = ref<UserInfo | null>(null);
const loading = ref(false);
const forceLogin = ref(false);
const login = async (username: string, password: string) => {
const login = async (email: string, password: string) => {
loading.value = true;
try {
const { data } = await apiLogin({ username, password });
const { data } = await apiLogin({ email, password });
token.value = data.access_token;
setToken(data.access_token);
await fetchMeAction();
forceLogin.value = false;
} finally {
loading.value = false;
}
@@ -31,6 +33,7 @@ export const useAuthStore = defineStore("auth", () => {
const logout = () => {
token.value = null;
user.value = null;
forceLogin.value = false;
clearToken();
const studyStore = useStudyStore();
studyStore.clearCurrentStudy();
@@ -40,8 +43,12 @@ export const useAuthStore = defineStore("auth", () => {
token,
user,
loading,
forceLogin,
login,
fetchMe: fetchMeAction,
logout,
requestReLogin: () => {
forceLogin.value = true;
},
};
});