import { collection, doc, type DocumentData, type FirestoreDataConverter, type PartialWithFieldValue, type QueryDocumentSnapshot, type SetOptions, type SnapshotOptions, type WithFieldValue, } from 'firebase/firestore'; import { db } from '@/lib/firebase'; import type { UserDocument } from '@/types/firestore'; const converter = (): FirestoreDataConverter => ({ toFirestore: (value: WithFieldValue | PartialWithFieldValue, options?: SetOptions) => value as DocumentData, fromFirestore: ( snapshot: QueryDocumentSnapshot, options: SnapshotOptions ) => snapshot.data(options) as T, }); export const collectionNames = { users: 'users', } as const; export const usersCollection = collection( db, collectionNames.users ).withConverter(converter()); export const userDoc = (uid: string) => doc(usersCollection, uid);