A preposition can be at the end of a relative clause beginning with that. Your first sentence is fine but the other one sounds awkward because there is such a lot between that and the preposition. There is nothing ungrammatical in the sentence, though.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.