mirror of
https://github.com/YunoHost/yunohost-portal.git
synced 2024-09-03 20:06:23 +02:00
add useUserInfo that auto fetch user data
This commit is contained in:
parent
34092041e6
commit
85c787f428
1 changed files with 22 additions and 0 deletions
|
@ -35,3 +35,25 @@ export async function useApi<T>(
|
|||
|
||||
return result as AsyncData<T, FetchError | null>
|
||||
}
|
||||
|
||||
export interface UserData {
|
||||
username: string
|
||||
fullname: string
|
||||
mail: string
|
||||
'mail-aliases': string[]
|
||||
'mail-forward': string[]
|
||||
groups: string[]
|
||||
apps: Record<string, { label: string; url: string }>
|
||||
}
|
||||
|
||||
export const useUserData = () => useState<UserData | undefined>('userData')
|
||||
|
||||
export async function useUserInfo() {
|
||||
const userData = useUserData()
|
||||
|
||||
if (!userData.value) {
|
||||
const { data } = await useApi('/me')
|
||||
userData.value = data.value as UserData
|
||||
}
|
||||
return userData as Ref<UserData>
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue