I used to do this by checking the X of player and the camera(invisible object)
Example: My screen's width is 3000 pixels. My viewport is 768x1366. So I will have conditions like these:
If player.X >= 384
OR player.X <= 2616 : Set camera X to player.X