It's very similar to buying a house - you don't get the mortgage first, you get a letter of pre-approval that says the bank is ready to give you a mortgage when you actually buy the thing.
It's even technically more amusing (a pre-approval letter is just the bank saying eh probably we can do this; it's not even required) - the seller will say "We will sell if you have the money", the bank will say "we will give the money if the house is worth X and you have Y downpayment, you will say "I have Y down payment if the bank will give me the money" and the appraiser will say "I think the house is worth X+1-5% (it is always just above the amount needed)".
Then you get a form of a financial standoff where each party checks that they're getting what they want, and you escrow/sign everything.