Files
wedding-planner/app/api/users/current-user/route.ts
2025-07-07 17:45:33 -04:00

20 lines
603 B
TypeScript

import { getServerSession } from "next-auth";
import { authOptions } from "../../auth/[...nextauth]/route";
import { NextResponse } from "next/server";
import { queries } from "@/lib/queries";
export async function GET() {
const session = await getServerSession(authOptions);
if (!session?.user.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const user = await queries.fetchCurrentUser(session.user.id)
if (!user) {
return NextResponse.json({ error: 'User not found' }, { status: 404 });
}
return NextResponse.json(user);
}