Create, organize, and manage photo albums with the album sidebar interface
Albums allow users to organize their photos into collections. The album management system is implemented through the AlbumSidebar component and backend API routes.
Before deleting an album, users are shown a confirmation dialog:
<AlertDialog open={!!deleteAlbumId} onOpenChange={() => setDeleteAlbumId(null)}> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Eliminar album</AlertDialogTitle> <AlertDialogDescription> Las fotos del album no se eliminaran, solo se moveran a "Todas las fotos". </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Cancelar</AlertDialogCancel> <AlertDialogAction onClick={() => { if (deleteAlbumId) onDeleteAlbum(deleteAlbumId) setDeleteAlbumId(null) }} > Eliminar </AlertDialogAction> </AlertDialogFooter> </AlertDialogContent></AlertDialog>
When an album is deleted, all photos in that album are moved to “no album” first:
// DELETE /api/albumsexport async function DELETE(request: NextRequest) { const supabase = await createClient() const { data: { user } } = await supabase.auth.getUser() if (!user) { return NextResponse.json({ error: 'No autorizado' }, { status: 401 }) } const { id } = await request.json() if (!id) { return NextResponse.json({ error: 'No se proporciono ID' }, { status: 400 }) } // Move photos in this album to "no album" await supabase .from('photos') .update({ album_id: null }) .eq('album_id', id) .eq('user_id', user.id) const { error } = await supabase .from('albums') .delete() .eq('id', id) .eq('user_id', user.id) if (error) { return NextResponse.json({ error: error.message }, { status: 500 }) } return NextResponse.json({ success: true })}
Location: app/api/albums/route.ts:59-94
When an album is deleted, photos are preserved by moving them to the “no album” state (album_id = null). Photos are never deleted when an album is removed.
All album operations use Supabase’s row-level security (RLS) to ensure users can only access their own albums. The user_id field is checked on every database operation.