Skip to main content

useUser()

useUser() returns the signed-in user's SCIM2 profile and methods that update and refresh it, using the WSO2 Identity Server Nuxt SDK (@asgardeo/nuxt).

Overview​

The server fetches the profile from WSO2 Identity Server while it renders the page, and <AsgardeoRoot> supplies it to useUser(). The module auto-imports useUser().

note

Call useUser() only in components that render inside <AsgardeoRoot>. Otherwise, it throws an error. When preferences.user.fetchUserProfile is false, the profile values are null and updateProfile() returns an unsuccessful result.

Usage​

<script setup lang="ts">
const { flattenedProfile, updateProfile } = useUser();

const changeNickname = async () => {
const result = await updateProfile({
payload: { nickName: 'Ace' },
});

if (!result.success) {
console.error(result.error);
}
};
</script>

<template>
<p>Email: {{ flattenedProfile?.emails }}</p>
<button @click="changeNickname">Change nickname</button>
</template>

API​

PropertyTypeDescription
profileReadonly<Ref<UserProfile | null>>The user profile from the SCIM2 /Me endpoint.
flattenedProfileReadonly<Ref<User | null>>The profile flattened into a map of attribute names to values.
schemasReadonly<Ref<Schema[] | null>>The SCIM2 schemas that describe the profile attributes.
updateProfile(requestConfig)(requestConfig: UpdateMeProfileConfig) => Promise<{ data: { user: User }; error: string; success: boolean }>Updates the profile through PATCH /api/auth/user/profile. The server sends requestConfig.payload to the SCIM2 /Me endpoint as the value of a replace operation. On success, it updates profile, flattenedProfile, and useAsgardeo().user.
revalidateProfile()() => Promise<void>Fetches the profile again from GET /api/auth/user/profile.
onUpdateProfile(user)(user: User) => voidUpdates the local profile state with the given user. updateProfile() calls this for you.

Was this page helpful?