Skip to content

Commit e1d1119

Browse files
fix(memberActions): use getAuthUserIdOrNull for safer user ID retrieval in updateLastActive function
fix(messageActions): return 0 instead of throwing error in getUnreadMessageCount for better error handling fix(Providers): handle errors gracefully when updating unread message count
1 parent 1514587 commit e1d1119

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/app/actions/memberActions.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { prisma } from '@/lib/prisma';
44
import { Member, Photo } from '@prisma/client';
55
import { addYears } from 'date-fns';
6-
import { getAuthUserId } from './authActions';
6+
import { getAuthUserId, getAuthUserIdOrNull } from './authActions';
77
import { GetMemberParams, PaginatedResponse } from '@/types';
88

99
function getAgeRange(ageRange: string): Date[] {
@@ -92,9 +92,13 @@ export async function getMemberPhotosByUserId(userId: string) {
9292
}
9393

9494
export async function updateLastActive() {
95-
const userId = await getAuthUserId();
96-
9795
try {
96+
const userId = await getAuthUserIdOrNull();
97+
98+
if (!userId) {
99+
return null;
100+
}
101+
98102
const result = await prisma.member.updateMany({
99103
where: { userId },
100104
data: { updated: new Date() }

src/app/actions/messageActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export async function getUnreadMessageCount() {
321321
})
322322
} catch (error) {
323323
console.log(error);
324-
throw error;
324+
return 0;
325325
}
326326
}
327327

src/components/Providers.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ export default function Providers({
3030

3131
useEffect(() => {
3232
if (!isUnreadCountSet.current && userId) {
33-
getUnreadMessageCount().then((count) => {
34-
updateUnreadCount(count);
35-
});
33+
getUnreadMessageCount()
34+
.then((count) => {
35+
updateUnreadCount(count);
36+
})
37+
.catch(() => {
38+
updateUnreadCount(0);
39+
});
3640
isUnreadCountSet.current = true;
3741
}
3842
}, [updateUnreadCount, userId]);

0 commit comments

Comments
 (0)