'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, Sparkles, Shield, Zap, ArrowLeft } from 'lucide-react'; 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 () => { 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(); }, onSuccess: () => { router.push('/dashboard'); }, onError: () => { setError('Failed to create account. Please try again.'); }, }); const loginMutation = useMutation({ mutationFn: async (token: string) => { 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(); throw new Error(data.error || 'Failed to login'); } return res.json(); }, 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()); } }; 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)} onKeyPress={(e) => e.key === 'Enter' && handleTokenLogin()} 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.

); }