NuxtN
Nuxt13mo ago
o.m

Value in composable is empty

I have this line of code that stores the user info

/composables/auth.ts
const user = ref<Form | null>(null);

const getCurrentUser = async (): Promise<void> => {
        try {
            const data = await $fetch("/api/auth/user", {
                method: "GET",
                headers: sessionHeader,
            });
            
            if (data.body && "user" in data.body) {
                user.value = data.body.user;
            }
        } catch (err) {
            console.log(err);
        }
    };

The code above is being called on /layouts/dashboard.vue That display's the name of the user
<template>
<DashboardHeader :user="user" />
(....)
const { user, getCurrentUser } = useAuth();
getCurrentUser();

I have this component located at /components/dashboard/CurriculumVit.vue but on the page it displays nothing.
<template>
{{ useAuth().user }}
</template>


What is the cause of {{ useAuth().user }} having no value when it was able to display the name of the user ?
Does useState solve this issue?
Was this page helpful?