From bdc7ed57b2d4b2756b13112857684594968bcc60 Mon Sep 17 00:00:00 2001 From: GGGGGangSub Date: Thu, 15 Jan 2026 23:12:55 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=ED=99=88=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=EC=97=90=EC=84=9C=20=EC=9C=A0=EC=A0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A5=BC=20=EA=B0=80=EC=A0=B8=EC=99=80=20=EC=B9=B4?= =?UTF-8?q?=EB=93=9C=20=EB=82=B4=EC=9A=A9=EC=9D=84=20=EA=B5=AC=EC=84=B1?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/(with-sidebar)/(home)/page.tsx | 53 +++++++++++++++++++----------- components/home/ProfileSection.tsx | 14 +++++--- lib/home/profileService.ts | 23 +++++++++++++ lib/home/todoService.ts | 2 +- 4 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 lib/home/profileService.ts diff --git a/app/(with-sidebar)/(home)/page.tsx b/app/(with-sidebar)/(home)/page.tsx index 5e0543c..a5a91c2 100644 --- a/app/(with-sidebar)/(home)/page.tsx +++ b/app/(with-sidebar)/(home)/page.tsx @@ -14,35 +14,20 @@ import { AddTodo, toggleTodoStatus, } from '@/lib/home/todoService'; +import { getProfile, Profile } from '@/lib/home/profileService'; import { User, onAuthStateChanged } from 'firebase/auth'; import { auth } from '@/lib/firebase'; const Page = () => { + const [profile, setProfile] = useState(null); const [todos, setTodos] = useState([]); + const [error, setError] = useState(null); // 현재 사용자 정보 const [currentUser, setCurrentUser] = useState(null); - // 사용자 로그인 상태 감지 - useEffect(() => { - const unsubscribe = onAuthStateChanged(auth, (user) => { - setCurrentUser(user); - }); - - return () => unsubscribe(); - }, []); - - // 사용자가 존재하면 데이터 불러옴 - useEffect(() => { - if (currentUser) { - loadTodos(currentUser.uid); - } else { - setTodos([]); - } - }, [currentUser]); - // 1. 할 일 목록 불러오기 const loadTodos = async (uid: string) => { try { @@ -86,6 +71,32 @@ const Page = () => { } }; + // 사용자 로그인 상태 감지 + useEffect(() => { + const unsubscribe = onAuthStateChanged(auth, (user) => { + setCurrentUser(user); + }); + + return () => unsubscribe(); + }, []); + + // 사용자가 존재하면 데이터 불러옴 + useEffect(() => { + if (currentUser) { + const loadData = async () => { + const userProfile = await getProfile(currentUser.uid); + setProfile(userProfile); + + await loadTodos(currentUser.uid); + }; + loadData(); + } else { + setTodos([]); + setProfile(null); + } + }, [currentUser]); + + // 유저 정보가 없을 시 if (!currentUser) { return (
@@ -94,13 +105,17 @@ const Page = () => { ); } + // 유저 정보가 있을 시 return (
{/* 1. Header */} {/* 2-1. ProfileSection */} - + {/* 2-2. GraphSection */} diff --git a/components/home/ProfileSection.tsx b/components/home/ProfileSection.tsx index c3d52a6..81b5811 100644 --- a/components/home/ProfileSection.tsx +++ b/components/home/ProfileSection.tsx @@ -1,10 +1,12 @@ +import { Profile } from '@/lib/home/profileService'; import Card from './Card'; interface ProfileSectionProps { className?: string; + profile: Profile | null; } -const ProfileSection = ({ className }: ProfileSectionProps) => { +const ProfileSection = ({ className, profile }: ProfileSectionProps) => { return (
@@ -14,12 +16,14 @@ const ProfileSection = ({ className }: ProfileSectionProps) => {
-

이건무

-

@mnmnnmm324

+

+ {profile?.nickname} +

+

{profile?.email}

- 38193일 연속 + {profile?.streakDays}일 연속 | - 12개 TIL + {profile?.tilCount}개 TIL
diff --git a/lib/home/profileService.ts b/lib/home/profileService.ts new file mode 100644 index 0000000..9cc608c --- /dev/null +++ b/lib/home/profileService.ts @@ -0,0 +1,23 @@ +import { doc, getDoc } from 'firebase/firestore'; +import { db } from '../firebase'; + +// 프로필 데이터 타입 +export interface Profile { + nickname: string; + email: string; + streakDays: number; + tilCount: number; + dailyGoal: number; +} + +// 1. 유저 프로필 정보 가져오기 +export const getProfile = async (uid: string): Promise => { + const userDocRef = doc(db, 'users', uid); + const docSnap = await getDoc(userDocRef); + + if (docSnap.exists()) { + return docSnap.data() as Profile; + } else return null; +}; + +// 2. 사용자 프로필 정보 업데이트 diff --git a/lib/home/todoService.ts b/lib/home/todoService.ts index b6113a5..228ee8a 100644 --- a/lib/home/todoService.ts +++ b/lib/home/todoService.ts @@ -21,7 +21,7 @@ export interface Todo { // 1. 할 일 목록 가져오기 export const fetchTodos = async (uid: string): Promise => { const todosCollectionPath = collection(db, 'users', uid, 'todos'); - const q = query(todosCollectionPath, orderBy('createAt', 'desc')); + const q = query(todosCollectionPath, orderBy('createAt', 'asc')); const snapshot = await getDocs(q); return snapshot.docs.map((doc) => ({ From dedbb05847b4ad64ba846902ca77cd91ace24f74 Mon Sep 17 00:00:00 2001 From: GGGGGangSub Date: Thu, 15 Jan 2026 23:40:58 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C?= =?UTF-8?q?=20=EB=B3=80=EC=88=98=20=EC=A0=9C=EA=B1=B0=20=EB=B0=8F=20?= =?UTF-8?q?=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20=EC=8B=9C=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C=EB=90=98=EB=8A=94=20api=20=EB=82=B4=EC=9D=98=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=ED=83=80=EC=9E=85=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/signup.api.ts | 4 ++++ lib/home/profileService.ts | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/api/signup.api.ts b/api/signup.api.ts index 4bc10fb..d284ad9 100644 --- a/api/signup.api.ts +++ b/api/signup.api.ts @@ -6,6 +6,8 @@ export type SignupPayload = { nickname: string; email: string; password: string; + streakDays: number; + tilCount: number; }; export async function signupWithEmail(p: SignupPayload) { @@ -15,6 +17,8 @@ export async function signupWithEmail(p: SignupPayload) { nickname: p.nickname, email: p.email, createdAt: serverTimestamp(), + streakDays: 0, + tilCount: 0, }); return cred.user; } diff --git a/lib/home/profileService.ts b/lib/home/profileService.ts index 9cc608c..f88daa6 100644 --- a/lib/home/profileService.ts +++ b/lib/home/profileService.ts @@ -7,7 +7,6 @@ export interface Profile { email: string; streakDays: number; tilCount: number; - dailyGoal: number; } // 1. 유저 프로필 정보 가져오기 From 2038c59d36c8e9e75aa44529b9d45e2df0a80534 Mon Sep 17 00:00:00 2001 From: GGGGGangSub Date: Thu, 15 Jan 2026 23:42:22 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=ED=95=84=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20try-catch=EB=AC=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/(with-sidebar)/(home)/page.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/(with-sidebar)/(home)/page.tsx b/app/(with-sidebar)/(home)/page.tsx index a5a91c2..338362c 100644 --- a/app/(with-sidebar)/(home)/page.tsx +++ b/app/(with-sidebar)/(home)/page.tsx @@ -84,10 +84,14 @@ const Page = () => { useEffect(() => { if (currentUser) { const loadData = async () => { - const userProfile = await getProfile(currentUser.uid); - setProfile(userProfile); - - await loadTodos(currentUser.uid); + try { + const userProfile = await getProfile(currentUser.uid); + setProfile(userProfile); + await loadTodos(currentUser.uid); + } catch (err) { + console.error(err); + setError('프로필 정보를 불러오는 데 실패하였습니다'); + } }; loadData(); } else {