import { NextRequest, NextResponse } from 'next/server' import { requireAuth } from '@/lib/auth' import { getNextInQueue, playSong } from '@/lib/player' export async function POST(request: NextRequest) { try { const user = await requireAuth() const nextSongId = await getNextInQueue(user.id) if (!nextSongId) { return NextResponse.json( { error: 'No next song in queue' }, { status: 404 } ) } await playSong(user.id, nextSongId, 'queue') return NextResponse.json( { message: 'Playing next song', songId: nextSongId }, { status: 200 } ) } catch (error) { console.error('Next song error:', error) if (error instanceof Error && error.message === 'Unauthorized') { return NextResponse.json( { error: 'Unauthorized' }, { status: 401 } ) } return NextResponse.json( { error: 'Failed to play next song' }, { status: 500 } ) } }