diff --git a/components/user/Avatar.vue b/components/user/Avatar.vue index a5878ac..9db2bb2 100644 --- a/components/user/Avatar.vue +++ b/components/user/Avatar.vue @@ -3,22 +3,10 @@ const user = useSupabaseUser() const supabase = useSupabaseClient() const userData = user.value; -var userAvatar = ""; - -await supabase - .from('profiles') - .select('id, avatar_url') - .eq('id', userData?.id) - .then(({ data, error }) => { - if (error) { - useToast().add({ title: 'User read failed', description: error.message }) - console.log(error) - } else { - if (data.length > 0) { - userAvatar = data[0].avatar_url; - } - } - }) +const { data: userAvatar } = await useAsyncData('userAvatar', async () => { + const { data } = await supabase.from('profiles').select('id, avatar_url').eq('id', userData?.id).single(); + return data.avatar_url +}); diff --git a/components/user/ProfileCard.vue b/components/user/ProfileCard.vue index 990cacf..7e151b5 100644 --- a/components/user/ProfileCard.vue +++ b/components/user/ProfileCard.vue @@ -12,21 +12,15 @@ const state = reactive({ username: "" }) -await supabase - .from('profiles') - .select('id, username') - .eq('id', userData?.id) - .then(({ data, error }) => { - if (error) { - console.log(error) - } else { - if (data.length > 0) { - state.username = data[0].username; - } - } - }) - - +const { data: userName, error } = await useAsyncData('userName', async () => { + const { data } = await supabase.from('profiles').select('id, username').eq('id', userData?.id).single(); + return data?.username +}); +state.username = userName; +// if (error) { +// console.log(error) +// useToast().add({ title: 'Get username failed', description: error.message }) +// } const onUpdate = async () => { const updates = { diff --git a/pages/teams.vue b/pages/teams.vue index 89f8f0f..5a01f54 100644 --- a/pages/teams.vue +++ b/pages/teams.vue @@ -10,7 +10,6 @@