import { setSessionCookie } from '../../lib/session'

export default defineEventHandler(async (event) => {
  const { password } = await readBody<{ password?: string }>(event)
  const config = useRuntimeConfig(event)
  if (!password || password !== config.portfolioPassword) {
    throw createError({ statusCode: 401, statusMessage: 'Mot de passe incorrect' })
  }
  setSessionCookie(event)
  return { authenticated: true }
})
