Car salesman sold to someone else after I bought it

I went to a Toyota dealership yesterday in Texas to get a Certified 2022 Toyota Corolla SE. I got financing through my credit union, so it took a while to get everything established, but I, my credit union, and the dealership signed all the paperwork. All the drafting was done. I did not leave with the car yesterday because it had a recall so it was getting fixed.

Today right before I was about to head to the dealership to pick it up, I receive a call from my salesperson that the car sold to someone else yesterday while I was there.

Is this even legal???? Everything was done, and I was only waiting on the car to get fixed. Now they are offering me a brand new 2023 Corolla SE for $800 more than what I paid for the certified one, but this feels like a cop out and not the best deal considering EVERYTHING was finished. I just had to pick it up today.

Any advice would be helpful.

Edit: Thanks for the advice! I am trying to get the brand new 2023 tomorrow.

Edit 2: I got a brand new 2023 SE for only $880 more than a 2022 certified pre-owned. I actually drove off with it this time. Glad they fixed this for me!