summaryrefslogtreecommitdiff
path: root/driver/src/utils/fetchUserDetails.ts
blob: 4577146dbbf47260d1271e2402f8ada17a1dfb5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { auth, db } from "@/firebase/firebase_config";
import { DocumentData, collection, getDocs, query, where } from "firebase/firestore";


export const fetchUserDetails = async (uid) => {
  try {
    const user = auth.currentUser;
    let data = null
    if (user) {
      const usersRef = collection(db, "users")
      const q = query(usersRef, where("uid", "==", uid))
      const querySnapshot = await getDocs(q);
      querySnapshot.forEach((doc: DocumentData) => {
        data = doc.data()
      });
      return data;
    } else {
      console.log("There is no user");
      return null;
    }
  } catch (error) {
    console.error('Error fetching user details:', error);
  }
};