mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.0 KiB
57 lines
1.0 KiB
import { acceptHMRUpdate, defineStore } from 'pinia' |
|
|
|
export const useUsers = defineStore('userStore', () => { |
|
const { api } = useApi() |
|
const { user } = useGlobal() |
|
|
|
const updateUserProfile = async ({ |
|
attrs, |
|
}: { |
|
attrs: { |
|
display_name?: string |
|
} |
|
}) => { |
|
if (!user.value) throw new Error('User is not defined') |
|
|
|
await api.userProfile.update(attrs) |
|
|
|
user.value = { |
|
...user.value, |
|
...attrs, |
|
} |
|
} |
|
|
|
const loadCurrentUser = async () => { |
|
const res = await api.auth.me() |
|
|
|
user.value = { |
|
...user.value, |
|
...res, |
|
roles: res.roles, |
|
project_roles: res.project_roles, |
|
workspace_roles: res.workspace_roles, |
|
} |
|
} |
|
|
|
watch( |
|
() => user.value?.id, |
|
(newId, oldId) => { |
|
if (!newId) return |
|
if (newId === oldId) return |
|
|
|
loadCurrentUser() |
|
}, |
|
{ |
|
immediate: true, |
|
}, |
|
) |
|
|
|
return { |
|
loadCurrentUser, |
|
updateUserProfile, |
|
} |
|
}) |
|
|
|
if (import.meta.hot) { |
|
import.meta.hot.accept(acceptHMRUpdate(useUsers as any, import.meta.hot)) |
|
}
|
|
|