From 7a196010214db6a1789760958eee5228374a7745 Mon Sep 17 00:00:00 2001 From: Alberto Duarte Delgado Date: Mon, 30 Mar 2026 18:12:23 +0100 Subject: logica perfil de usuario --- src/features/profile/services/profileService.ts | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/features/profile/services/profileService.ts (limited to 'src/features/profile/services/profileService.ts') diff --git a/src/features/profile/services/profileService.ts b/src/features/profile/services/profileService.ts new file mode 100644 index 0000000..566c3fa --- /dev/null +++ b/src/features/profile/services/profileService.ts @@ -0,0 +1,45 @@ +// src/features/profile/services/profileService.ts + +import { doc, getDoc, updateDoc } 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; + + await updateDoc(doc(db, 'users', uid), { + displayName, + ...(photoURL !== undefined ? { photoURL } : {}), + }); + + if (auth.currentUser) { + await updateProfile(auth.currentUser, { + displayName, + ...(photoURL !== undefined ? { photoURL } : {}), + }); + } + }, +}; -- cgit v1.2.3-54-g00ecf