mirror of
https://github.com/urosran/cally.git
synced 2025-07-10 07:07:16 +00:00
31 lines
808 B
TypeScript
31 lines
808 B
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import { UserProfile } from "@/hooks/firebase/types/profileTypes";
|
|
import firestore from "@react-native-firebase/firestore";
|
|
|
|
export const useGetUserById = (uid: string | undefined) => {
|
|
return useQuery({
|
|
queryKey: ["getUserById", uid],
|
|
queryFn: async (): Promise<UserProfile | null> => {
|
|
if (!uid) return null;
|
|
|
|
try {
|
|
const doc = await firestore()
|
|
.collection("Profiles")
|
|
.doc(uid)
|
|
.get();
|
|
|
|
if (!doc.exists) return null;
|
|
|
|
const data = doc.data();
|
|
return {
|
|
...data,
|
|
uid: doc.id,
|
|
} as UserProfile;
|
|
} catch (error) {
|
|
console.error("Error retrieving user:", error);
|
|
return null;
|
|
}
|
|
},
|
|
enabled: !!uid
|
|
});
|
|
}; |