Since 2015, immigration authorities in Germany, for example, have been allowed to search the devices of people who are required to leave the country in order to establish their identity and country of origin. This often happens during official visits. Therefore, leave your device at home or get a burner phone.
They’re allowed to search your phone if it is unlocked. Curiously, that includes first unlocking it by holding it up to your face or using other biometric data of yours. They can NOT force you to give them your PIN or password (edit: or force you to enter them yourself). Act accordingly.