diff --git a/apps/hackathon/src/app/auth/login/page-original.tsx b/apps/hackathon/src/app/auth/login/page-original.tsx deleted file mode 100644 index c615f92..0000000 --- a/apps/hackathon/src/app/auth/login/page-original.tsx +++ /dev/null @@ -1,89 +0,0 @@ -import { FC, ReactElement, useEffect, useState } from 'react'; -import { Button } from '@imphnen-frontend-service/ui/atoms'; -import { useNavigate } from 'react-router'; -import { useGitHubAuth } from '@imphnen-frontend-service/service'; -import { useSession } from '@imphnen-frontend-service/utils'; -import { GithubOutlined } from '@ant-design/icons'; - -const LoginPage: FC = (): ReactElement => { - console.log('[LoginPage] Rendering...'); - - const navigate = useNavigate(); - const { signInWithGitHub } = useGitHubAuth(); - const [isGithubLoading, setIsGithubLoading] = useState(false); - const { isAuthenticated } = useSession(); - - console.log('[LoginPage] isAuthenticated:', isAuthenticated); - - useEffect(() => { - console.log('[LoginPage] useEffect - isAuthenticated:', isAuthenticated); - if (isAuthenticated) { - console.log('[LoginPage] Redirecting to dashboard...'); - navigate('/dashboard'); - } - }, [isAuthenticated, navigate]); - - const handleGithubLogin = async () => { - try { - setIsGithubLoading(true); - console.log('[Login] Initiating GitHub OAuth...'); - - const result = await signInWithGitHub(); - console.log('[Login] OAuth result:', result); - - // Check if we got a redirect URL - if (result?.url) { - console.log('[Login] Redirecting to GitHub OAuth:', result.url); - // Supabase should handle the redirect automatically - // If we're still here after 2 seconds, manually redirect - setTimeout(() => { - if (result.url) { - globalThis.location.href = result.url; - } - }, 2000); - } else { - console.error('[Login] No OAuth URL returned'); - setIsGithubLoading(false); - } - } catch (error) { - console.error('[Login] GitHub login failed:', error); - setIsGithubLoading(false); - } - }; - - return ( -
-
-
-

- Welcome to Hackathon -

-

- Sign in with your GitHub account to join or create your hackathon team -

-
- - - -
-

- By signing in, you agree to our Terms of Service and Privacy Policy -

-
-
-
- ); -}; - -export default LoginPage; diff --git a/apps/hackathon/src/app/layout.tsx b/apps/hackathon/src/app/layout.tsx index 24da90e..cb034c0 100644 --- a/apps/hackathon/src/app/layout.tsx +++ b/apps/hackathon/src/app/layout.tsx @@ -14,18 +14,14 @@ export default function RootLayout() { const checkAuth = async () => { const pathname = location.pathname; - console.log('[Layout] Checking auth for route:', pathname); - // Allow hackathon pages without checks if (pathname.startsWith('/hackathons')) { - console.log('[Layout] Public route, allowing access'); setIsChecking(false); return; } // Allow auth callback without checks if (pathname === '/auth/callback') { - console.log('[Layout] Auth callback, allowing access'); setIsChecking(false); return; } @@ -43,27 +39,23 @@ export default function RootLayout() { if (isPublicAuthPage) { // If already authenticated and not on password reset pages, redirect to dashboard if (session && pathname !== '/auth/reset-password') { - console.log('[Layout] Already authenticated, redirecting to dashboard'); navigate('/dashboard', { replace: true }); setIsChecking(false); return; } // Allow unauthenticated access - console.log('[Layout] Public auth page, allowing access'); setIsChecking(false); return; } // Home page - allow everyone to view the landing page if (pathname === '/') { - console.log('[Layout] Landing page, allowing access'); setIsChecking(false); return; } // Require authentication for all other routes if (!session) { - console.log('[Layout] No session, redirecting to login'); navigate('/auth/login', { replace: true }); setIsChecking(false); return; @@ -87,17 +79,15 @@ export default function RootLayout() { const hasLocation = !!userData?.location; if (!hasLocation) { - console.log('[Layout] User needs onboarding, redirecting'); navigate('/onboarding/user', { replace: true }); setIsChecking(false); return; } } catch (error) { - console.error('[Layout] Unexpected error checking onboarding:', error); + // Silently handle error } } - console.log('[Layout] Auth check passed'); setIsChecking(false); }; diff --git a/apps/hackathon/src/app/onboarding/user/page.tsx b/apps/hackathon/src/app/onboarding/user/page.tsx index a8b7f3e..0a7cb6d 100644 --- a/apps/hackathon/src/app/onboarding/user/page.tsx +++ b/apps/hackathon/src/app/onboarding/user/page.tsx @@ -12,6 +12,7 @@ import { useAuthStore, } from '@imphnen-frontend-service/service'; import { zodResolver } from '@hookform/resolvers/zod'; +import { toast } from 'sonner'; import { CitySelect } from '../../../components/city-select'; @@ -69,41 +70,32 @@ const UserOnboardingPage: FC = (): ReactElement => { const onSubmit = form.handleSubmit(async (data) => { try { - console.log('[Onboarding] Starting submission...', data); let avatarUrl = session?.user?.avatar || null; // Upload avatar if a new file was selected if (avatarFile) { - console.log('[Onboarding] Uploading avatar...'); const uploadResult = await uploadAvatar(avatarFile); avatarUrl = uploadResult.data.url; - console.log('[Onboarding] Avatar uploaded:', avatarUrl); } // Update user in Supabase - console.log('[Onboarding] Updating user in Supabase...'); - const result = await updateUser({ + await updateUser({ fullname: data.fullname, avatar: avatarUrl, location: data.location, bio: data.bio, skills: data.skills, }); - console.log('[Onboarding] User updated successfully:', result); // Wait a bit for the onSuccess handler to update localStorage // The updateUser mutation's onSuccess handler updates the Zustand store and localStorage await new Promise((resolve) => setTimeout(resolve, 100)); - console.log('[Onboarding] Navigating to dashboard...'); // Use window.location for a full page reload to ensure middleware sees updated localStorage globalThis.location.href = '/dashboard'; } catch (error) { - console.error('[Onboarding] Onboarding failed:', error); - alert( - `Onboarding failed: ${ - error instanceof Error ? error.message : 'Unknown error' - }` + toast.error( + error instanceof Error ? error.message : 'Onboarding failed. Please try again.' ); } }); diff --git a/apps/hackathon/src/app/teams/[teamId]/page.tsx b/apps/hackathon/src/app/teams/[teamId]/page.tsx index fb9f035..699fd6b 100644 --- a/apps/hackathon/src/app/teams/[teamId]/page.tsx +++ b/apps/hackathon/src/app/teams/[teamId]/page.tsx @@ -30,8 +30,6 @@ const TeamDashboardPage: FC = (): ReactElement => { const isMember = members.some((member: any) => member.user_id === currentUserId); const canInvite = isLeader && members.length < MAX_TEAM_MEMBERS; - console.log('Leader check:', { currentUserId, leaderId: team?.leader_id, isLeader }); - const handleInviteMember = async (e: React.FormEvent) => { e.preventDefault(); if (!inviteEmail.trim() || isInviting) return; diff --git a/apps/hackathon/src/middleware.ts b/apps/hackathon/src/middleware.ts index 28ed9e0..d5001ae 100644 --- a/apps/hackathon/src/middleware.ts +++ b/apps/hackathon/src/middleware.ts @@ -37,8 +37,6 @@ export const middleware = async ({ request }: LoaderFunctionArgs) => { const url = new URL(request.url); const pathname = url.pathname; - console.log('[Middleware] Checking route:', pathname); - // Get session from Supabase (authoritative source) const { data: { session: supabaseSession }, error: sessionError } = await supabase.auth.getSession(); @@ -86,10 +84,8 @@ export const middleware = async ({ request }: LoaderFunctionArgs) => { let hasLocation = false; if (cached && (now - cached.timestamp) < CACHE_DURATION) { - console.log('[Middleware] Using cached onboarding status'); hasLocation = cached.hasLocation; } else { - console.log('[Middleware] Fetching fresh onboarding status'); const { data: userData, error: userError } = await supabase .from('users') .select('location')