← back to Letsbegin

app/api/auth/logout/route.ts

19 lines

import { NextResponse } from 'next/server'
import { AUTH_CONFIG } from '@/lib/auth'
import { cookies } from 'next/headers'

export async function POST() {
  try {
    const cookieStore = await cookies()
    cookieStore.delete(AUTH_CONFIG.sessionName)

    return NextResponse.json({
      success: true,
      message: 'Logged out successfully'
    })
  } catch (error) {
    console.error('Logout error:', error)
    return NextResponse.json({ error: 'Logout failed' }, { status: 500 })
  }
}