'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { useMutation } from '@tanstack/react-query'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { Separator } from '@/components/ui/separator'; import { LogIn, Shield, Zap, ArrowLeft, Activity, CalendarCheck } from 'lucide-react'; interface AuthResponse { success?: boolean; token?: string; userId?: string; error?: string; } export default function Welcome() { const router = useRouter(); const [showTokenInput, setShowTokenInput] = useState(false); const [tokenInput, setTokenInput] = useState(''); const [error, setError] = useState(''); const createAccountMutation = useMutation({ mutationFn: async (): Promise => { const res = await fetch('/api/auth', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'create' }), }); if (!res.ok) throw new Error('Failed to create account'); return res.json() as Promise; }, onSuccess: () => { router.push('/dashboard'); }, onError: () => { setError('Failed to create account. Please try again.'); }, }); const loginMutation = useMutation({ mutationFn: async (token: string): Promise => { const res = await fetch('/api/auth', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'login', token }), }); if (!res.ok) { const data = (await res.json()) as AuthResponse; throw new Error(data.error ?? 'Failed to login'); } return res.json() as Promise; }, onSuccess: () => { router.push('/dashboard'); }, onError: (error: Error) => { setError(error.message || 'Failed to login. Please check your token.'); }, }); const handleTokenLogin = () => { if (tokenInput.trim()) { setError(''); loginMutation.mutate(tokenInput.trim()); } }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { handleTokenLogin(); } }; return (
📅
Track Every Day Build better habits, one day at a time. No email or password required.
{!showTokenInput ? (
{/* Features */}

Privacy-first: No personal data required

Instant access with a unique token

Track positive, neutral, or negative habits

{/* Actions */}
or
) : (
{ setTokenInput(e.target.value); }} onKeyDown={handleKeyDown} className="border-zinc-800 bg-zinc-900 placeholder:text-zinc-600" autoFocus />

Enter the token you saved from your previous session

)} {error && ( {error} )}

Your habits are tied to a unique token. Save it to access your data across devices. No account creation or personal information required.

); }