Server error: Cannot read properties of undefined (reading 'next')