feat: 添加用户设置功能,支持修改昵称和邮箱,重构相关路由和组件

This commit is contained in:
2025-12-21 01:11:53 +07:00
parent 2e42bbc278
commit a4034b6b78
22 changed files with 620 additions and 225 deletions

View File

@@ -0,0 +1,12 @@
export function beforeApp() {
const { updateProfile } = useUserStore();
const { initializeWallet } = useWalletStore();
return new Promise<void>((resolve) => {
useAuth().then(() => {
updateProfile();
initializeWallet();
resolve();
});
});
}

View File

@@ -1,15 +1,30 @@
import type { UnwrapRef } from "vue";
import { safeClient } from "@/api";
import { authClient } from "@/auth";
export function useAuth() {
// Better Auth 提供的 session
const session = authClient.useSession();
type User = UnwrapRef<ReturnType<typeof authClient.useSession> extends Promise<infer R extends { data: any }> ? R["data"] : never>;
const user = computed(() => session.value.data?.user);
const isAuthenticated = computed(() => !!session.value.data);
export function useAuth() {
const session = ref<User | null>(null);
if (session.value === undefined) {
safeClient(authClient.getSession()).then((res) => {
session.value = res.data.value;
});
}
const user = computed(() => session.value?.user);
const isAuthenticated = computed(() => !!session.value);
return {
user,
session,
isAuthenticated,
then(onfulfilled: (value: User | null) => void) {
return safeClient(authClient.getSession()).then((res) => {
session.value = res.data.value;
onfulfilled(session.value);
});
},
};
}