suna / frontend /src /components /GoogleSignIn.tsx
R-Kentaren's picture
Upload folder using huggingface_hub
4efde5d verified
'use client';
import { useState } from 'react';
import { createClient } from '@/lib/supabase/client';
import { toast } from 'sonner';
import { FcGoogle } from "react-icons/fc";
import { Loader2 } from 'lucide-react';
interface GoogleSignInProps {
returnUrl?: string;
}
export default function GoogleSignIn({ returnUrl }: GoogleSignInProps) {
const [isLoading, setIsLoading] = useState(false);
const supabase = createClient();
const handleGoogleSignIn = async () => {
try {
setIsLoading(true);
const { error } = await supabase.auth.signInWithOAuth({
provider: 'google',
options: {
redirectTo: `${window.location.origin}/auth/callback${
returnUrl ? `?returnUrl=${encodeURIComponent(returnUrl)}` : ''
}`,
},
});
if (error) {
throw error;
}
} catch (error: any) {
console.error('Google sign-in error:', error);
toast.error(error.message || 'Failed to sign in with Google');
setIsLoading(false);
}
};
return (
<button
onClick={handleGoogleSignIn}
disabled={isLoading}
className="w-full h-12 flex items-center justify-center text-sm font-medium tracking-wide rounded-full bg-background text-foreground border border-border hover:bg-accent/30 transition-all duration-200 disabled:opacity-60 disabled:cursor-not-allowed font-sans"
type="button"
>
{isLoading ? (
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
) : (
<FcGoogle className="w-4 h-4 mr-2" />
)}
<span className="font-medium">
{isLoading ? 'Signing in...' : 'Continue with Google'}
</span>
</button>
);
}