Title:
Vue 3 Composition API fetch returns undefined for nested session object properties
Body:
I am working on a Vue 3 component using the
syntax. The goal of this component is to fetch the currently logged-in user's profile from an Express.js backend (/api/me) usingfetchwithcredentials: 'include'to pass the session cookie.While the network request completes successfully, I am having trouble correctly extracting and displaying the user's role/type, and I want to make sure my asynchronous
onMountedlifecycle hook handles the data correctly.Here is my
UserDisplay.vuecomponent:Belépve mint: {{ user_name }}
Felhasználó típusa: {{ user_type }}
My questions:
In my backend, the
/api/meendpoint sends back{ session: req.session }. However, the user type is determined by an external function. Should I modify the backend response, or is there a cleaner way to map the fetched reactive properties in Vue?What is the best practice for handling a loading state in Vue 3 while the
async onMountedfetch is still running, to prevent the UI from flashing empty values?Any advice on improving this component would be appreciated!