'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import * as z from 'zod'; import { useAuthStore } from '@/stores/auth-store'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Loader2, Eye, EyeOff } from 'lucide-react'; const loginSchema = z.object({ email: z.string().email('Invalid email address'), password: z.string().min(1, 'Password is required'), }); type LoginForm = z.infer; export default function LoginPage() { const router = useRouter(); const { login, isLoading, isAuthenticated } = useAuthStore(); const [showPassword, setShowPassword] = useState(false); const { register, handleSubmit, formState: { errors, isSubmitting }, } = useForm({ resolver: zodResolver(loginSchema), }); // Redirect if already authenticated useEffect(() => { if (isAuthenticated) { router.replace('/dashboard/tenants'); } }, [isAuthenticated, router]); const onSubmit = async (data: LoginForm) => { const result = await login(data.email, data.password); if (result.success) { if (result.requiresTfa) { // Redirect to TFA verification page router.push('/auth/verify-tfa'); } else { // Check if user has TFA setup pending const { user } = useAuthStore.getState(); if (user?.tfa_setup_pending) { router.push('/dashboard/settings'); } else { router.push('/dashboard/tenants'); } } } }; if (isAuthenticated) { return null; // Prevent flash before redirect } return (
GT
GT 2.0 Control Panel Sign in to your super administrator account

Super Admin Access Only
Only super administrators can access the Control Panel. Tenant admins and users should use the main tenant application.

{errors.email && (

{errors.email.message}

)}
{errors.password && (

{errors.password.message}

)}
); }