'use client'; import React, { useState } from 'react'; import { useRouter, useSearchParams } from 'next/navigation'; import Link from 'next/link'; import { Card, CardContent } from '@/components/ui/Card'; import { Input } from '@/components/ui/Input'; import { Button } from '@/components/ui/Button'; import { useTranslation } from '@/hooks/useTranslation'; import { useCsrf } from '@/hooks/useCsrf'; export default function LoginClient() { const router = useRouter(); const searchParams = useSearchParams(); const { t } = useTranslation(); const { fetchWithCsrf, loading: csrfLoading } = useCsrf(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); try { const response = await fetchWithCsrf('/api/auth/simple-login', { method: 'POST', body: JSON.stringify({ email, password }), }); const data = await response.json(); if (response.ok && data.success) { // Store user in localStorage for client-side localStorage.setItem('user', JSON.stringify(data.user)); // Track successful login with PostHog try { const { identifyUser, trackEvent } = await import('@/components/PostHogProvider'); identifyUser(data.user.id, { email: data.user.email, name: data.user.name, plan: data.user.plan || 'FREE', }); trackEvent('user_login', { method: 'email', email: data.user.email, }); } catch (error) { console.error('PostHog tracking error:', error); } // Check for redirect parameter const redirectUrl = searchParams.get('redirect') || '/dashboard'; router.push(redirectUrl); router.refresh(); } else { setError(data.error || 'Invalid email or password'); } } catch (err) { setError('An error occurred. Please try again.'); } finally { setLoading(false); } }; const handleGoogleSignIn = () => { // Redirect to Google OAuth API route window.location.href = '/api/auth/google'; }; return (
QR Master QR Master

Welcome Back

Sign in to your account

← Back to Home
{error && (
{error}
)} setEmail(e.target.value)} placeholder="you@example.com" required /> setPassword(e.target.value)} placeholder="••••••••" required />
Forgot password?
Or continue with

Don't have an account?{' '} Sign up

By signing in, you agree to our{' '} Privacy Policy

); }