From a28af1f629bcefe21ccab2177074a87603eef3de Mon Sep 17 00:00:00 2001 From: Gib Date: Mon, 16 Jun 2025 05:33:57 -0500 Subject: [PATCH] Think it might be ready to deploy. I'm sure there are a lot of bugs, but I at least am no longe finding them --- src/components/context/Auth.tsx | 3 ++- src/lib/actions/public.ts | 36 ++++++++++++++++++++++++++++++--- src/lib/actions/status.ts | 10 ++++----- src/lib/hooks/public.ts | 4 ++-- src/lib/hooks/status.ts | 6 +++--- 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/components/context/Auth.tsx b/src/components/context/Auth.tsx index 529b8ee..c3175c1 100644 --- a/src/components/context/Auth.tsx +++ b/src/components/context/Auth.tsx @@ -10,6 +10,7 @@ import React, { } from 'react'; import { getProfile, + getProfileWithAvatar, getUser, updateProfile as updateProfileAction, } from '@/lib/hooks'; @@ -50,7 +51,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { } const userResponse = await getUser(); - const profileResponse = await getProfile(); + const profileResponse = await getProfileWithAvatar(); if (!userResponse.success || !profileResponse.success) { setUser(null); diff --git a/src/lib/actions/public.ts b/src/lib/actions/public.ts index acef04a..07d90af 100644 --- a/src/lib/actions/public.ts +++ b/src/lib/actions/public.ts @@ -1,10 +1,40 @@ -'use server'; +'use client'; import { createServerClient, type Profile } from '@/utils/supabase'; -import { getSignedUrl, getUser } from '@/lib/hooks'; +import { getSignedUrl, getUser } from '@/lib/actions'; import type { Result } from '.'; export const getProfile = async ( + userId: string | null = null, +): Promise> => { + try { + if (userId == null) { + const user = await getUser(); + if (!user.success || !user.data.id) + throw new Error('User not found'); + userId = user.data.id; + } + const supabase = await createServerClient(); + const { data, error } = await supabase + .from('profiles') + .select('*') + .eq('id', userId) + .single(); + if (error) throw error; + + return { success: true, data: data as Profile }; + } catch (error) { + return { + success: false, + error: + error instanceof Error + ? error.message + : 'Unknown error getting profile', + }; + } +}; + +export const getProfileWithAvatar = async ( userId: string | null = null ): Promise> => { try { @@ -48,7 +78,7 @@ type updateProfileProps = { full_name?: string; email?: string; avatar_url?: string; - provider?: string + provider?: string; }; export const updateProfile = async ({ diff --git a/src/lib/actions/status.ts b/src/lib/actions/status.ts index 31c560e..af6f1c7 100644 --- a/src/lib/actions/status.ts +++ b/src/lib/actions/status.ts @@ -1,7 +1,7 @@ 'use server'; import { createServerClient } from '@/utils/supabase'; import type { Profile, Result } from '@/utils/supabase'; -import { getUser, getProfile, getSignedUrl } from '@/lib/actions'; +import { getUser, getProfileWithAvatar, getSignedUrl } from '@/lib/actions'; export type UserWithStatus = { id?: string; @@ -67,9 +67,9 @@ export const getRecentUsersWithStatuses = async (): Promise< for (const userWithStatus of filtered) { if (userWithStatus.user.avatar_url) userWithStatus.user.avatar_url = - await getAvatarUrl(userWithStatus.updated_by?.avatar_url); + await getAvatarUrl(userWithStatus.user.avatar_url); if (userWithStatus.updated_by?.avatar_url) - userWithStatus.user.avatar_url = + userWithStatus.updated_by.avatar_url = await getAvatarUrl(userWithStatus.updated_by?.avatar_url); filteredWithAvatars.push(userWithStatus); } @@ -115,7 +115,7 @@ export const updateStatuses = async ( ): Promise> => { try { const supabase = await createServerClient(); - const profileResponse = await getProfile(); + const profileResponse = await getProfileWithAvatar(); if (!profileResponse.success) throw new Error('Not authenticated!'); const user = profileResponse.data; @@ -155,7 +155,7 @@ export const updateUserStatus = async ( ): Promise> => { try { const supabase = await createServerClient(); - const profileResponse = await getProfile(); + const profileResponse = await getProfileWithAvatar(); if (!profileResponse.success) throw new Error(`Not authenticated! ${profileResponse.error}`); const userProfile = profileResponse.data; diff --git a/src/lib/hooks/public.ts b/src/lib/hooks/public.ts index b3ddf3a..2b9350c 100644 --- a/src/lib/hooks/public.ts +++ b/src/lib/hooks/public.ts @@ -4,7 +4,7 @@ import { createClient, type Profile } from '@/utils/supabase'; import { getSignedUrl, getUser } from '@/lib/hooks'; import type { Result } from '.'; -export const getOriginalProfile = async ( +export const getProfile = async ( userId: string | null = null, ): Promise> => { try { @@ -34,7 +34,7 @@ export const getOriginalProfile = async ( } }; -export const getProfile = async ( +export const getProfileWithAvatar = async ( userId: string | null = null ): Promise> => { try { diff --git a/src/lib/hooks/status.ts b/src/lib/hooks/status.ts index 80d3f5c..7d48467 100644 --- a/src/lib/hooks/status.ts +++ b/src/lib/hooks/status.ts @@ -1,7 +1,7 @@ 'use client'; import { createClient } from '@/utils/supabase'; import type { Profile, Result } from '@/utils/supabase'; -import { getUser, getOriginalProfile, getSignedUrl } from '@/lib/hooks'; +import { getUser, getProfileWithAvatar, getSignedUrl } from '@/lib/hooks'; export type UserWithStatus = { id?: string; @@ -115,7 +115,7 @@ export const updateStatuses = async ( ): Promise> => { try { const supabase = createClient(); - const profileResponse = await getOriginalProfile(); + const profileResponse = await getProfileWithAvatar(); if (!profileResponse.success) throw new Error('Not authenticated!'); const user = profileResponse.data; @@ -155,7 +155,7 @@ export const updateUserStatus = async ( ): Promise> => { try { const supabase = createClient(); - const profileResponse = await getOriginalProfile(); + const profileResponse = await getProfileWithAvatar(); if (!profileResponse.success) throw new Error(`Not authenticated! ${profileResponse.error}`); const userProfile = profileResponse.data;