summaryrefslogtreecommitdiffstats
path: root/src/features/profile/services/profileService.ts
diff options
context:
space:
mode:
authorAlberto Duarte Delgado <alberto@albertoduarte.com>2026-03-30 18:12:23 +0100
committerAlberto Duarte Delgado <alberto@albertoduarte.com>2026-03-30 18:12:23 +0100
commit7a196010214db6a1789760958eee5228374a7745 (patch)
treee8d936b04bdf72acbe9c5910fee95add0bef7e94 /src/features/profile/services/profileService.ts
parent174f1acd46c4ffbde88c04465e8fa6b6810ce113 (diff)
logica perfil de usuario
Diffstat (limited to 'src/features/profile/services/profileService.ts')
-rw-r--r--src/features/profile/services/profileService.ts45
1 files changed, 45 insertions, 0 deletions
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<UserProfile | null> {
+ 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<void> {
+ 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 } : {}),
+ });
+ }
+ },
+};