Add password-based auth with JWT and remember-me
This commit is contained in:
1 parent
89deb869ab
commit
0042e7150c
10 files changed
+281
-37
No files matched your search
@@ -0,0 +1,81 @@
|
||||
import { useState } from 'react';
|
||||
import { useAuthStore } from '@/stores/useAuthStore';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { Loader2, Lock } from 'lucide-react';
|
||||
|
||||
export function LoginPage() {
|
||||
const [password, setPassword] = useState('');
|
||||
const [remember, setRemember] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const login = useAuthStore((s) => s.login);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!password.trim()) return;
|
||||
setError('');
|
||||
setLoading(true);
|
||||
try {
|
||||
await login(password, remember);
|
||||
} catch {
|
||||
setError('Invalid password');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-background">
|
||||
<div className="w-full max-w-sm space-y-6 rounded-xl border border-border bg-card p-8 shadow-lg">
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<div className="flex h-12 w-12 items-center justify-center rounded-full bg-primary/10">
|
||||
<Lock className="h-6 w-6 text-primary" />
|
||||
</div>
|
||||
<h1 className="text-xl font-bold">Showy</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Enter your password to continue
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="password">Password</Label>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="••••••••"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<Switch
|
||||
checked={remember}
|
||||
onCheckedChange={setRemember}
|
||||
id="remember"
|
||||
/>
|
||||
<Label htmlFor="remember" className="text-sm cursor-pointer">
|
||||
Remember me
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<p className="text-sm text-destructive text-center">{error}</p>
|
||||
)}
|
||||
|
||||
<Button type="submit" className="w-full" disabled={loading}>
|
||||
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||
Unlock
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import type { Settings } from '@/types';
|
||||
const settingsSchema = z.object({
|
||||
tmdbApiKey: z.string().min(1, 'TMDB API key is required'),
|
||||
backPort: z.coerce.number().int().positive(),
|
||||
authPassword: z.string().optional(),
|
||||
});
|
||||
|
||||
function formatOrphanResult(result: OrphanResult): string {
|
||||
@@ -258,7 +259,11 @@ export function SettingsPage() {
|
||||
} = useForm({
|
||||
resolver: zodResolver(settingsSchema),
|
||||
values: settings
|
||||
? { tmdbApiKey: settings.tmdbApiKey, backPort: settings.backPort }
|
||||
? {
|
||||
tmdbApiKey: settings.tmdbApiKey,
|
||||
backPort: settings.backPort,
|
||||
authPassword: settings.authPassword || '',
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
|
||||
@@ -320,6 +325,16 @@ export function SettingsPage() {
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="authPassword">Auth Password</Label>
|
||||
<Input
|
||||
id="authPassword"
|
||||
type="password"
|
||||
{...register('authPassword')}
|
||||
placeholder="Leave empty to disable"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={!isDirty || updateSettings.isPending}
|
||||
|
||||
Reference in new issue
Block a user