refactor: remove login/auth for public dashboard
Deploy to VPS / deploy (push) Failing after 34s

- Remove login page, redirect / to /dashboard directly
- Remove AuthProvider, DashboardGuard from dashboard layout
- Remove use-auth hook and auth API module
- Remove X-Admin-Password header from API client
- Remove logout button from sidebar
This commit is contained in:
asepharyana
2026-07-26 11:30:27 +07:00
parent 5e01ec0806
commit f9f1313ccd
7 changed files with 17 additions and 258 deletions
+13 -41
View File
@@ -7,32 +7,8 @@ import { Header } from "@/components/layout/header";
import { MobileTabBar } from "@/components/layout/mobile-tab-bar";
import { Sidebar } from "@/components/layout/sidebar";
import { MascotChatbot } from "@/features/mascot/mascot-chatbot";
import { AuthProvider, useAuth } from "@/lib/hooks/use-auth";
import { WsProvider } from "@/lib/ws/context";
function DashboardGuard({ children }: { children: React.ReactNode }) {
const { authenticated, loading } = useAuth();
const router = useRouter();
useEffect(() => {
if (!loading && !authenticated) {
router.push("/");
}
}, [authenticated, loading, router]);
if (loading) {
return (
<div className="flex min-h-screen items-center justify-center">
<div className="size-6 animate-spin rounded-full border-2 border-primary border-t-transparent" />
</div>
);
}
if (!authenticated) return null;
return <>{children}</>;
}
function DashboardShell({ children }: { children: React.ReactNode }) {
const searchParams = useSearchParams();
const router = useRouter();
@@ -49,7 +25,7 @@ function DashboardShell({ children }: { children: React.ReactNode }) {
const tabParam = searchParams.get("tab");
if (tabParam) {
restored.current = true;
return; // explicit tab in URL — don't override
return;
}
uiStateApi
.get()
@@ -89,21 +65,17 @@ export default function DashboardLayout({
children: React.ReactNode;
}) {
return (
<AuthProvider>
<DashboardGuard>
<WsProvider>
<Suspense
fallback={
<div className="flex min-h-screen items-center justify-center">
<div className="size-6 animate-spin rounded-full border-2 border-primary border-t-transparent" />
</div>
}
>
<DashboardShell>{children}</DashboardShell>
</Suspense>
<MascotChatbot />
</WsProvider>
</DashboardGuard>
</AuthProvider>
<WsProvider>
<Suspense
fallback={
<div className="flex min-h-screen items-center justify-center">
<div className="size-6 animate-spin rounded-full border-2 border-primary border-t-transparent" />
</div>
}
>
<DashboardShell>{children}</DashboardShell>
</Suspense>
<MascotChatbot />
</WsProvider>
);
}
+3 -101
View File
@@ -1,103 +1,5 @@
"use client";
import { redirect } from "next/navigation";
import { Loader2, Shield } from "lucide-react";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import { login } from "@/lib/api";
export default function LoginPage() {
const [password, setPassword] = useState("");
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const [checking, setChecking] = useState(true);
const router = useRouter();
useEffect(() => {
const stored = localStorage.getItem("admin-password");
if (stored) {
login(stored)
.then((ok) => {
if (ok) router.replace("/dashboard");
else setChecking(false);
})
.catch(() => setChecking(false));
} else {
setChecking(false);
}
}, [router]);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError("");
setLoading(true);
try {
const ok = await login(password);
if (ok) {
localStorage.setItem("admin-password", password);
router.push("/dashboard");
} else {
setError("Invalid password");
}
} catch {
setError("Connection failed. Is the backend running?");
} finally {
setLoading(false);
}
};
if (checking) {
return (
<div className="flex min-h-screen items-center justify-center bg-background">
<Loader2 className="size-6 animate-spin text-muted-foreground" />
</div>
);
}
return (
<div className="flex min-h-screen items-center justify-center bg-background p-4">
<div className="w-full max-w-sm space-y-6">
<div className="flex flex-col items-center gap-2 text-center">
<div className="flex size-12 items-center justify-center rounded-full bg-primary/10">
<Shield className="size-6 text-primary" />
</div>
<h1 className="text-2xl font-semibold tracking-tight">Bete</h1>
<p className="text-sm text-muted-foreground">
Discord Moderation Dashboard
</p>
</div>
<form onSubmit={handleSubmit} className="space-y-4">
<div className="space-y-2">
<label
htmlFor="password"
className="text-sm font-medium leading-none"
>
Admin Password
</label>
<input
id="password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Enter admin password"
className="flex h-9 w-full rounded-lg border border-input bg-background px-3 py-1 text-sm shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:opacity-50"
disabled={loading}
/>
</div>
{error && <p className="text-sm text-destructive">{error}</p>}
<button
type="submit"
disabled={loading || !password}
className="inline-flex w-full items-center justify-center rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow-sm transition-colors hover:bg-primary/90 disabled:pointer-events-none disabled:opacity-50"
>
{loading ? <Loader2 className="mr-2 size-4 animate-spin" /> : null}
{loading ? "Signing in…" : "Sign in"}
</button>
</form>
</div>
</div>
);
export default function RootPage() {
redirect("/dashboard?tab=messages");
}