Smartphone search during a border crossing
I see stories on Reddit of American border agents requiring visitors to unlock their smartphones when crossing the U.S. border in ports of entry, I.e. international airports. I am curious about my rights if a border agent asks me to unlock my phone. Do I have the right to refuse? Or what is my best recourse in that situation?
I am an American citizen. I will be flying in with my wife, who is a legal permanent resident. I would assume that she has fewer options to refuse that request.
Can someone please shed some light on it?