Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
'use client';
import { useState } from 'react';
import { useTranslations } from 'next-intl';
import { useSearchParams } from 'next/navigation';
import { useRouter, Link } from '@/i18n/navigation';
import { createClient } from '@/lib/supabase/client';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { PasswordInput } from '@/components/ui/password-input';
import { Label } from '@/components/ui/label';
import { toast } from 'sonner';
import { ArrowRight, Loader2 } from 'lucide-react';
import { OAuthButtons } from '@/components/auth/oauth-buttons';
import { OrDivider } from '@/components/auth/or-divider';
import { track } from '@/lib/analytics';
import { safeNextPath } from '@/lib/auth-next';
export function SignInForm() {
const t = useTranslations('auth');
const router = useRouter();
const searchParams = useSearchParams();
// The page the visitor was on before signing in; only one of ours.
const nextPath = safeNextPath(searchParams.get('next'));
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [isLoading, setIsLoading] = useState(false);
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
setIsLoading(true);
const supabase = createClient();
const { error } = await supabase.auth.signInWithPassword({
email,
password,
});
if (error) {
const msg = error.message.toLowerCase();
if (msg.includes('email not confirmed')) {
toast.error(t('errors.emailNotConfirmed'));
} else if (msg.includes('invalid login credentials')) {
toast.error(t('errors.invalidCredentials'));
} else {
toast.error(t('errors.generic'));
}
setIsLoading(false);
return;
}
// identify() runs centrally in AuthProvider on the SIGNED_IN auth event,
// so the form just needs to capture the funnel event.
track('signin_completed', { source: 'email' });
router.push(nextPath);
router.refresh();
}
return (
<div className="space-y-6">
<form onSubmit={handleSubmit} className="space-y-5">
<div className="space-y-2">
<Label htmlFor="email">{t('workEmail')}</Label>
<Input
id="email"
type="email"
placeholder={t('emailPlaceholder')}
value={email}
onChange={(e) => setEmail(e.target.value)}
required
autoComplete="email"
disabled={isLoading}
className="h-11"
/>
</div>
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label htmlFor="password">{t('password')}</Label>
<Link
href="/forgot-password"
className="text-sm text-muted-foreground hover:text-primary underline-offset-4 hover:underline"
>
{t('forgotPassword')}
</Link>
</div>
<PasswordInput
id="password"
placeholder={t('passwordPlaceholder')}
value={password}
onChange={(e) => setPassword(e.target.value)}
required
autoComplete="current-password"
disabled={isLoading}
className="h-11"
/>
</div>
<Button type="submit" className="h-11 w-full text-base" disabled={isLoading}>
{isLoading ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
{t('signingIn')}
</>
) : (
<>
{t('signIn')}
<ArrowRight className="h-4 w-4" />
</>
)}
</Button>
</form>
<OrDivider label={t('orContinueWith')} />
<OAuthButtons next={searchParams.get('next') ? nextPath : null} />
</div>
);
}