import { eventHandler } from 'h3'
import { getUserSession, sessionHooks } from '~/server/utils/session'
import type { UserSessionRequired } from '~/types/auth'

export default eventHandler(async (event) => {
  const session = await getUserSession(event)

  if (session.user) {
    await sessionHooks.callHookParallel('fetch', session as UserSessionRequired, event)
  }

  return session
})