summaryrefslogtreecommitdiff
path: root/driver/src/utils/fetchUserDetails.ts
blob: a2d5cb6e9c4510abe14b7e33cb731f0407afee3c (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
25
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()
        console.log(doc.id, " => ", doc.data());
      });
      return data;
    } else {
      console.log("There is no user");
      return null;
    }
  } catch (error) {
    console.error('Error fetching user details:', error);
  }
};