23 lines
644 B
JavaScript
23 lines
644 B
JavaScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { auth } from "@/lib/auth";
|
|
import { getUnreadNotificationCount } from "@/lib/notifications";
|
|
|
|
export async function GET(request) {
|
|
try {
|
|
const session = await auth();
|
|
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
|
|
const unreadCount = await getUnreadNotificationCount(session.user.id);
|
|
|
|
return NextResponse.json({ unreadCount });
|
|
} catch (error) {
|
|
console.error("Error fetching unread notification count:", error);
|
|
return NextResponse.json(
|
|
{ error: "Internal server error" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
} |