// src/features/profile/services/profileService.ts import { doc, getDoc, setDoc } from 'firebase/firestore'; import { updateProfile } from 'firebase/auth'; import { db, auth } from '@/shared/lib/firebase/config'; import { UserProfile } from '@/features/profile/types'; export const profileService = { async getMyProfile(uid: string): Promise { const snapshot = await getDoc(doc(db, 'users', uid)); if (!snapshot.exists()) { return null; } const data = snapshot.data(); return { uid, email: data.email ?? '', displayName: data.displayName ?? '', photoURL: data.photoURL ?? '', }; }, async updateMyProfile(params: { uid: string; displayName: string; photoURL?: string; }): Promise { const { uid, displayName, photoURL } = params; const currentUser = auth.currentUser; await setDoc(doc(db, 'users', uid), { email: currentUser?.email ?? '', displayName, ...(photoURL !== undefined ? { photoURL } : {}), }, { merge: true }); if (currentUser) { await updateProfile(currentUser, { displayName, ...(photoURL !== undefined ? { photoURL } : {}), }); } }, };