- Install sonner; <Toaster> mounted in Providers, auto-tracks theme. - Toasts replace inline result Alerts across ServerControls, PlayerManager, BackupManager, ModManager (install/remove/restore/delete/start/stop). - PlayerManager: optimistic op/deop/whitelist/ban/pardon via onMutate + rollback; UI updates instantly before RCON round-trip. - Modrinth search results now show author + "updated Xd ago" with full timestamp on hover; downloads on its own row. - New /api/mods/updates endpoint: per-installed-mod Modrinth latest-version lookup (parallel, 30min memo). Amber "Update available" badge rendered next to installed mod rows when filenames differ. - PlayerAvatar + Modrinth icons migrated to next/image (unoptimized, size hints) — fewer layout shifts. - Login page surfaces ?error= + NextAuth error codes (CredentialsSignin, SessionRequired, etc.), preserves callbackUrl, adds autocomplete hints and role="alert". Wrapped in Suspense per Next 16 requirement. - Snapshots + backups show relative "Xh ago" with exact timestamp on hover via new lib/time.ts helper. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
117 lines
3.4 KiB
TypeScript
117 lines
3.4 KiB
TypeScript
"use client";
|
|
|
|
import { signIn } from "next-auth/react";
|
|
import { useRouter, useSearchParams } from "next/navigation";
|
|
import { Suspense, useEffect, useState } from "react";
|
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Label } from "@/components/ui/label";
|
|
|
|
const ERROR_MESSAGES: Record<string, string> = {
|
|
CredentialsSignin: "Invalid username or password.",
|
|
SessionRequired: "Please sign in to continue.",
|
|
Verification: "Sign-in link is invalid or expired.",
|
|
AccessDenied: "You don't have access.",
|
|
Configuration: "Auth configuration error — contact the server admin.",
|
|
};
|
|
|
|
function LoginInner() {
|
|
const router = useRouter();
|
|
const params = useSearchParams();
|
|
const [error, setError] = useState("");
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const qErr = params.get("error");
|
|
if (qErr) setError(ERROR_MESSAGES[qErr] || `Sign-in failed (${qErr}).`);
|
|
}, [params]);
|
|
|
|
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
|
e.preventDefault();
|
|
setLoading(true);
|
|
setError("");
|
|
|
|
const formData = new FormData(e.currentTarget);
|
|
|
|
const res = await signIn("credentials", {
|
|
username: formData.get("username"),
|
|
password: formData.get("password"),
|
|
redirect: false,
|
|
});
|
|
|
|
if (res?.error) {
|
|
setError(ERROR_MESSAGES[res.error] || "Invalid credentials.");
|
|
setLoading(false);
|
|
} else {
|
|
const callback = params.get("callbackUrl") || "/admin";
|
|
router.push(callback);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="flex-1 flex items-center justify-center p-3 sm:p-6">
|
|
<Card className="w-full max-w-sm">
|
|
<CardHeader className="text-center">
|
|
<CardTitle className="text-xl">Admin Login</CardTitle>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
<div className="space-y-2">
|
|
<Label htmlFor="username">Username</Label>
|
|
<Input
|
|
id="username"
|
|
name="username"
|
|
type="text"
|
|
autoComplete="username"
|
|
required
|
|
autoFocus
|
|
/>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<Label htmlFor="password">Password</Label>
|
|
<Input
|
|
id="password"
|
|
name="password"
|
|
type="password"
|
|
autoComplete="current-password"
|
|
required
|
|
/>
|
|
</div>
|
|
|
|
{error && (
|
|
<div
|
|
role="alert"
|
|
className="rounded-md border border-red-500/30 bg-red-500/5 p-2.5 text-destructive text-sm text-center"
|
|
>
|
|
{error}
|
|
</div>
|
|
)}
|
|
|
|
<Button type="submit" disabled={loading} className="w-full">
|
|
{loading ? "Signing in..." : "Sign in"}
|
|
</Button>
|
|
</form>
|
|
|
|
<div className="mt-4 text-center">
|
|
<a
|
|
href="/"
|
|
className="text-sm text-muted-foreground hover:text-foreground transition"
|
|
>
|
|
Back to dashboard
|
|
</a>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function LoginPage() {
|
|
return (
|
|
<Suspense fallback={null}>
|
|
<LoginInner />
|
|
</Suspense>
|
|
);
|
|
}
|