From 149c0704fec02b755308c4ebb0162dbee04ab246 Mon Sep 17 00:00:00 2001
From: "gpt-engineer-app[bot]"
<159125892+gpt-engineer-app[bot]@users.noreply.github.com>
Date: Mon, 13 Oct 2025 17:22:56 +0000
Subject: [PATCH] Refactor: Simplify auth and profile handling
---
src/components/auth/AuthButtons.tsx | 22 +----
src/components/settings/AccountProfileTab.tsx | 4 +-
src/components/settings/DataExportTab.tsx | 7 +-
src/components/settings/LocationTab.tsx | 12 +--
src/components/settings/PrivacyTab.tsx | 12 +--
src/hooks/useAuth.tsx | 81 +------------------
src/hooks/useProfile.tsx | 50 ++++++++++++
src/pages/Profile.tsx | 6 +-
src/pages/UserSettings.tsx | 6 +-
9 files changed, 78 insertions(+), 122 deletions(-)
create mode 100644 src/hooks/useProfile.tsx
diff --git a/src/components/auth/AuthButtons.tsx b/src/components/auth/AuthButtons.tsx
index 39053ed6..1d53c31c 100644
--- a/src/components/auth/AuthButtons.tsx
+++ b/src/components/auth/AuthButtons.tsx
@@ -5,16 +5,13 @@ import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
import { User, Settings, LogOut } from 'lucide-react';
import { useAuth } from '@/hooks/useAuth';
+import { useProfile } from '@/hooks/useProfile';
import { useToast } from '@/hooks/use-toast';
import { AuthModal } from './AuthModal';
export function AuthButtons() {
- const {
- user,
- profile,
- loading,
- signOut
- } = useAuth();
+ const { user, loading: authLoading, signOut } = useAuth();
+ const { data: profile, isLoading: profileLoading } = useProfile(user?.id);
const navigate = useNavigate();
const {
toast
@@ -43,7 +40,7 @@ export function AuthButtons() {
};
// Show loading skeleton only during initial auth check
- if (loading) {
+ if (authLoading) {
return (
@@ -83,17 +80,6 @@ export function AuthButtons() {
>
);
}
- // Debug logging for avatar rendering
- console.log('[AuthButtons] Component render:', {
- hasUser: !!user,
- hasProfile: !!profile,
- hasAvatarUrl: !!profile?.avatar_url,
- avatarUrl: profile?.avatar_url,
- displayName: profile?.display_name,
- username: profile?.username,
- loading
- });
-
return