'use client' import { useAuth } from '@thedaviddias/auth' import { Button } from '@thedaviddias/design-system/button' import { logger } from '@thedaviddias/logging' import { ArrowLeft, CheckCircle, Github } from 'lucide-react' import Link from 'next/link' import { useRouter } from 'next/navigation' import { useEffect, useState } from 'react' import { toast } from 'sonner' import { Card } from '@/components/ui/card' /** * Page for connecting a GitHub account to the user's profile */ export default function ConnectGitHubPage() { const { user, isLoaded } = useAuth() const router = useRouter() const [isConnecting, setIsConnecting] = useState(false) // Check if user already has GitHub connected via OAuth const hasGitHubAuth = user?.externalAccounts?.some(account => account.provider === 'oauth_github') useEffect(() => { if (!isLoaded) return // If user doesn't exist, redirect to login if (!user) { router.push('/login?redirect=/auth/connect-github') return } // If user already has GitHub, redirect to profile if (hasGitHubAuth) { router.push('/profile?message=GitHub account already connected') return } }, [isLoaded, user, hasGitHubAuth, router]) /** * Initiates the GitHub account connection flow */ const handleConnectGitHub = async () => { setIsConnecting(true) try { // Redirect to login with GitHub to connect account window.location.href = '/login?provider=github&redirect=/profile?message=GitHub account connected successfully' } catch (error) { logger.error(error instanceof Error ? error : new Error(String(error)), { data: error, tags: { type: 'page', page: 'connect-github' } }) toast.error('Failed to connect GitHub account. Please try again.') setIsConnecting(false) } } // Loading state while checking user if (!user) { return (
Loading...
) } // Already connected state if (hasGitHubAuth) { return (

GitHub Connected!

Your GitHub account is already connected to your profile.

) } return (
{/* Back button */}

Connect Your GitHub Account

Upgrade your account to unlock direct project submissions and get proper credit for your contributions.

Benefits of connecting GitHub:

  • Create pull requests under your GitHub account
  • Get proper attribution for your contributions
  • Faster submission process
  • Access to contributor features

This will merge your accounts. You'll keep your existing profile and data.

) }