import { NextRequest, NextResponse } from 'next/server' import { prisma } from '@/lib/prisma' import { getCurrentUser, revokeAllSessions, revokeAllRefreshTokens } from '@/lib/auth' export async function POST(request: NextRequest) { try { // Get current user const user = await getCurrentUser() if (!user) { return NextResponse.json( { error: 'Not authenticated' }, { status: 401 } ) } // Revoke all sessions and refresh tokens for this user await Promise.all([ revokeAllSessions(user.id), revokeAllRefreshTokens(user.id), ]) // Clear the auth cookie const response = NextResponse.json( { message: 'Logged out successfully' }, { status: 200 } ) response.cookies.set('auth-token', '', { httpOnly: true, secure: process.env.NODE_ENV === 'production', sameSite: 'lax', maxAge: 0, path: '/', }) return response } catch (error) { console.error('Logout error:', error) return NextResponse.json( { error: 'Failed to logout' }, { status: 500 } ) } }