Adapt frontend to SAM API: RUT auth, new types, helpdesk endpoints
- Login: RUT-based (SAM auth) instead of email - API client: updated all endpoints to /api/helpdesk/* - Types: match SAM response format (nombre, apPaterno, perfil) - Dashboard: uses new DashboardStats with dailyCounts - Tickets: title instead of subject, requesterName/assigneeName - KB: categoryName/authorName instead of nested objects - Removed register page (SAM manages users)
This commit is contained in:
1 parent
0cca57f21e
commit
f56f6365d2
11 files changed
+285
-718
No files matched your search
+10
-11
@@ -5,7 +5,7 @@ import { getMe, login as apiLogin, type User } from "./api";
|
||||
|
||||
interface AuthContextType {
|
||||
user: User | null;
|
||||
login: (email: string, password: string) => Promise<void>;
|
||||
login: (rut: string, password: string) => Promise<void>;
|
||||
logout: () => void;
|
||||
isAuthenticated: boolean;
|
||||
isLoading: boolean;
|
||||
@@ -27,22 +27,21 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
const token = localStorage.getItem("helpdesk_token");
|
||||
if (token) {
|
||||
getMe()
|
||||
.then((u) => {
|
||||
setUser(u);
|
||||
})
|
||||
.catch(() => {
|
||||
localStorage.removeItem("helpdesk_token");
|
||||
})
|
||||
.then((u) => setUser(u))
|
||||
.catch(() => localStorage.removeItem("helpdesk_token"))
|
||||
.finally(() => setIsLoading(false));
|
||||
} else {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const login = useCallback(async (email: string, password: string) => {
|
||||
const { token, user } = await apiLogin(email, password);
|
||||
localStorage.setItem("helpdesk_token", token);
|
||||
setUser(user);
|
||||
const login = useCallback(async (rut: string, password: string) => {
|
||||
const result = await apiLogin(rut, password);
|
||||
if (!result.success || !result.token) {
|
||||
throw new Error(result.message || "Credenciales inválidas");
|
||||
}
|
||||
localStorage.setItem("helpdesk_token", result.token);
|
||||
if (result.user) setUser(result.user);
|
||||
}, []);
|
||||
|
||||
const logout = useCallback(() => {
|
||||
|
||||
Reference in new issue
Block a user