feat: 更新 @riwa/api-types 依赖至 0.0.49,优化用户数据处理逻辑
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
import type { UserData, UserProfileData } from "@/api/types";
|
||||
import type { UserProfileData } from "@/api/types";
|
||||
import { client, safeClient } from "@/api";
|
||||
|
||||
interface State {
|
||||
user: UserData | null;
|
||||
userProfile: UserProfileData | null;
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore("user", () => {
|
||||
const token = useStorage<string | null>("user-token", null);
|
||||
const state = reactive<State>({
|
||||
user: null,
|
||||
userProfile: null,
|
||||
});
|
||||
|
||||
@@ -17,8 +15,7 @@ export const useUserStore = defineStore("user", () => {
|
||||
|
||||
async function updateProfile() {
|
||||
const { data } = await safeClient(client.api.user.profile.get(), { silent: true });
|
||||
state.userProfile = data.value?.userProfile || null;
|
||||
state.user = data.value?.user || null;
|
||||
state.userProfile = data.value || null;
|
||||
}
|
||||
|
||||
function setToken(value: string) {
|
||||
@@ -28,7 +25,6 @@ export const useUserStore = defineStore("user", () => {
|
||||
function signOut() {
|
||||
token.value = null;
|
||||
state.userProfile = null;
|
||||
state.user = null;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user