Many people assume that their boss cannot fire them unless there is "good cause." Sadly, most people are wrong. In 49 states, employment is "at-will" which means either you or your employer can end the employer-employee relationship. This post will go over what this means for you.
"At-will" means that your employment lasts only as long as you or your boss wants it to. It also means that either one of you can end it for almost any reason. For example, if you walk into your job and see the walls are painted blue, you hate the color blue, so you quit. That is entirely valid. Similarly, if your boss wakes up in a bad mood and fires you 'out of the blue,' that is also acceptable. Your employer does not need a reason to fire you, he or she can fire you at will.
There are some limitations. For example, most states, including California, do not allow employers to fire employees who refuse to violate the law during their employment. This exception is known as the "public policy" exception, essentially, you cannot be fired for acting in the public's interest. This limitation includes reporting bad employer behavior, such as safety violations. Additionally, you cannot be fired for undertaking a mandatory civic duty, like jury duty.
The other major exception is whenever there is a contract. Many courts will infer an "implied contract" if the employee was subject to an employee handbook or oral agreement. If the employee handbook prescribes hiring and firing procedures, the employer must obey those procedures or risk liability for breach of contract.
If you believe you were fired as some form of retaliation, then you may want to speak to a lawyer. No one can fire you for exercising your public duty to report a dangerous condition. A lawyer can help secure you compensation for your lost wages.