refactor: remove login/auth for public dashboard
Deploy to VPS / deploy (push) Failing after 34s
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:
@@ -1,78 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
createContext,
|
||||
type ReactNode,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
} from "react";
|
||||
import { login } from "@/lib/api";
|
||||
|
||||
interface AuthContextValue {
|
||||
authenticated: boolean;
|
||||
loading: boolean;
|
||||
login: (password: string) => Promise<boolean>;
|
||||
logout: () => void;
|
||||
}
|
||||
|
||||
const AuthContext = createContext<AuthContextValue | null>(null);
|
||||
|
||||
export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const [authenticated, setAuthenticated] = useState(false);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const password = localStorage.getItem("admin-password");
|
||||
if (password) {
|
||||
// Verify stored password still works
|
||||
login(password)
|
||||
.then((ok) => {
|
||||
setAuthenticated(ok);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch(() => {
|
||||
localStorage.removeItem("admin-password");
|
||||
setLoading(false);
|
||||
});
|
||||
} else {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleLogin = useCallback(async (password: string) => {
|
||||
const ok = await login(password);
|
||||
if (ok) {
|
||||
localStorage.setItem("admin-password", password);
|
||||
setAuthenticated(true);
|
||||
}
|
||||
return ok;
|
||||
}, []);
|
||||
|
||||
const handleLogout = useCallback(() => {
|
||||
localStorage.removeItem("admin-password");
|
||||
setAuthenticated(false);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<AuthContext.Provider
|
||||
value={{
|
||||
authenticated,
|
||||
loading,
|
||||
login: handleLogin,
|
||||
logout: handleLogout,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useAuth(): AuthContextValue {
|
||||
const ctx = useContext(AuthContext);
|
||||
if (!ctx) {
|
||||
throw new Error("useAuth must be used within an AuthProvider");
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
Reference in New Issue
Block a user