feat: Fleet Forge UEM - device management, agent, remote desktop (VNC), TLS reverse proxy

This commit is contained in:
Pepe44DEV
2026-09-06 22:09:28 +00:00
commit db16ad5cc1
154 changed files with 22920 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
"use client";
import { useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import { api } from "@/lib/api";
interface User {
id: string;
email: string;
displayName: string;
role: string;
}
export function useAuth() {
const [user, setUser] = useState<User | null>(null);
const [loading, setLoading] = useState(true);
const router = useRouter();
useEffect(() => {
const token = api.getToken();
if (!token) {
setLoading(false);
return;
}
fetch(`${process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000/api"}/v1/auth/me`, {
headers: { Authorization: `Bearer ${token}` },
})
.then((res) => res.json())
.then((data) => {
if (data.success) {
setUser(data.data);
} else {
api.setToken(null);
}
})
.catch(() => api.setToken(null))
.finally(() => setLoading(false));
}, []);
const login = async (email: string, password: string) => {
const res = await api.post<{ token: string; user: User }>("/v1/auth/login", {
email,
password,
});
if (res.success && res.data) {
api.setToken(res.data.token);
setUser(res.data.user);
return true;
}
return false;
};
const logout = () => {
api.setToken(null);
setUser(null);
router.push("/login");
};
return { user, loading, login, logout };
}