first commit

This commit is contained in:
2026-05-29 10:23:25 +03:00
commit e4b25fe4b7
48 changed files with 9112 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
import { useState, FormEvent } from 'react';
import { Link, Navigate } from 'react-router-dom';
import { useAuth } from '@/hooks/useAuth';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
export default function LoginPage() {
const { user, login } = useAuth();
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
if (user) return <Navigate to="/feed" replace />;
const handleSubmit = async (e: FormEvent) => {
e.preventDefault();
setError('');
setLoading(true);
try {
await login(username, password);
} catch (err: any) {
setError(err.response?.data?.error || 'Login failed');
} finally {
setLoading(false);
}
};
return (
<div className="flex min-h-screen items-center justify-center p-4">
<div className="w-full max-w-sm animate-fade-in">
<div className="text-center mb-8">
<h1 className="text-2xl font-semibold tracking-tight">Catstagram</h1>
<p className="text-sm text-muted-foreground mt-1">Sign in to your account</p>
</div>
<form onSubmit={handleSubmit} className="space-y-3">
<Input
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder="Username"
required
autoFocus
className="h-10 text-sm"
/>
<Input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Password"
required
className="h-10 text-sm"
/>
{error && <p className="text-sm text-destructive">{error}</p>}
<Button type="submit" className="w-full h-10" disabled={loading}>
{loading ? 'Signing in...' : 'Sign in'}
</Button>
</form>
<p className="mt-6 text-center text-sm text-muted-foreground">
No account?{' '}
<Link to="/register" className="font-medium underline-offset-4 hover:underline">
Register
</Link>
</p>
</div>
</div>
);
}