Files
aegis/src/hooks/useUserInformations.ts
T
2026-08-04 16:51:00 +02:00

30 lines
1.0 KiB
TypeScript

import { pb } from "@/services/pocketbase";
import type { Company } from "@/types/Company";
import type { User } from "@/types/User";
import { useEffect, useState } from "react";
export const useUserInformations = () => {
const [user, setUser] = useState<User | null>(null);
const [company, setCompany] = useState<Company | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const fetchInformations = async () => {
setIsLoading(true);
try {
const userRecords = await pb.collection('aegis_users').getFullList<User>();
setUser(userRecords[0]);
const companyRecords = await pb.collection('aegis_companies').getFullList<Company>();
setCompany(companyRecords[0])
} catch (err) {
setError("Erreur lors de la récupération des infos utilisateur :"+err);
} finally {
setIsLoading(false);
}
};
fetchInformations();
}, []);
return { user, company, isLoading, error };
};