useProfile
Composable for reading and updating user-management profiles.
Overview
useProfile() provides profile read and update methods for the user-management API. When no user UUID is supplied, both methods use the currently authenticated user from useAccAuthUser().
Pass a user UUID explicitly when working with another profile, such as from an administrative user-management flow. Reading or updating another user's profile only succeeds when the authenticated user has the required user-management permission.
Usage
const { getProfile, updateProfile } = useProfile()
const response = await getProfile()
const avatarUrl = response.userProfile.avatarUrl
await updateProfile({
firstName: 'John',
lastName: 'Doe',
})getProfile
Reads a profile from GET /usermgmt/user?userUuid={userUuid}. Without an argument, it reads the current authenticated user's profile. Results are cached by user UUID for the current Nuxt session and shared by all consumers of useProfile(). When the profile has an avatar key, getProfile() resolves its private CDN URL and adds avatarUrl to the returned userProfile.
// Uses useAccAuthUser().value.userUuid
const profile = await getProfile()
console.log(profile.userProfile, profile.userProfile.avatarUrl)
// Explicit UUID for another profile. Requires permission.
const otherProfile = await getProfile('user_...')
console.log(otherProfile.userProfile.email, otherProfile.userProfile.avatarUrl)updateProfile
Updates a profile with POST /usermgmt/user/{userUuid}. First and last names are optional; send null to clear a value and omit a field to preserve it. A successful update also keeps the cached profile synchronized.
// Update the current authenticated user's names
await updateProfile({
firstName: 'John',
lastName: 'Doe',
})
// Clear firstName and preserve lastName
await updateProfile({
firstName: null,
})
// Update another profile. Requires permission.
await updateProfile({
userUuid: 'user_...',
firstName: 'Jane',
lastName: 'Doe',
})