import { useState, useEffect } from 'react' import { Button } from '@/components/ui/button' import { Separator } from '@/components/ui/separator' import { apiService } from '@/lib/api' export function OAuthButtons() { const [providers, setProviders] = useState([]) const [loading, setLoading] = useState(null) useEffect(() => { const fetchProviders = async () => { try { const response = await apiService.getOAuthProviders() setProviders(response.providers) } catch (error) { console.error('Failed to fetch OAuth providers:', error) } } fetchProviders() }, []) const handleOAuthLogin = async (provider: string) => { setLoading(provider) try { const response = await apiService.getOAuthUrl(provider) // Store state in sessionStorage for verification sessionStorage.setItem('oauth_state', response.state) // Redirect to OAuth provider window.location.href = response.authorization_url } catch (error) { console.error(`${provider} OAuth failed:`, error) setLoading(null) } } const getProviderIcon = (provider: string) => { switch (provider) { case 'google': return ( ) case 'github': return ( ) default: return null } } const getProviderName = (provider: string) => { return provider.charAt(0).toUpperCase() + provider.slice(1) } if (providers.length === 0) { return null } return (
Or continue with
{providers.map((provider) => ( ))}
) }