feat: 添加用户设置功能,支持修改昵称和邮箱,重构相关路由和组件
This commit is contained in:
12
src/composables/beforeApp.ts
Normal file
12
src/composables/beforeApp.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export function beforeApp() {
|
||||
const { updateProfile } = useUserStore();
|
||||
const { initializeWallet } = useWalletStore();
|
||||
|
||||
return new Promise<void>((resolve) => {
|
||||
useAuth().then(() => {
|
||||
updateProfile();
|
||||
initializeWallet();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user