Unfortunately, this is legal. Maybe not fair, but legal. The reason is that most employment arrangements are what is known as "at will". This means that you can choose to work for an employer or no,t and an employer can hire or fire you for any reason or no reason at all. The exceptions to this would be if this action was not allowed by virtue of a union agreement, employment contract, or an official stated company policy.  Also, discrimination must not be a factor in your termination.  Absent any of these circumstance your firing was lawful.