Most of us have experienced this. Usually it's a shock.
Just remember, business is a vile thing and will throw you under the bus at any time. It's much easier said than done, but, no matter how well your j*b seems to be going, "they" will drop you like yesterday's garbage through no fault of your own. Again, much easier said than done, but do not take it as a personal failing. It's not you, it's them.
Treat your next j*b and any others in the future, as simply the way you happen to be making money on that particular day. No matter what the boss says, good or bad, always keep looking for a new situation. Never become complacent. They're going to try to stab you in the back. Prepare for the blow and be ready to spin away
when it comes.
Think of the pleasure you will feel when, as the personnel guy is in the process of giving you the ax, you pull out your cell phone and accept a new position before he even has the chance to tell you to clean out you desk.
Without missing a beat, you will be on your way and it will gall the stuffin' out of management.