import { getServerSession } from 'next-auth'
import { authOptions } from './auth'
import { NextResponse } from 'next/server'

export async function getSession() {
  return await getServerSession(authOptions)
}

export async function getCurrentUserId(): Promise<string | null> {
  const session = await getSession()
  return (session?.user as any)?.id || null
}

export async function requireAuth() {
  const session = await getSession()
  if (!session?.user) {
    return NextResponse.json({ error: 'Non authentifié' }, { status: 401 })
  }
  return null
}
