import type { SessionData } from '@/types/Auth'
import { cookies } from 'next/headers'
import { NextResponse } from 'next/server'
import { getIronSession } from 'iron-session'
import { sessionOptions } from '@/libs/session'
import { tracking } from '@/libs/tracking'

export async function GET(request: Request) {
  const cookieStore = await cookies()
  const session = await getIronSession<SessionData>(cookieStore, sessionOptions)

  tracking({
    url: '/api/auth/logout',
    data: JSON.stringify({
      userId: session.userId,
    }),
  })
  session.destroy()
  // return redirect('/login')

  return NextResponse.json({ code: 200, message: 'Logout successful' })
}
