How do we pray with a person when they are approaching the
end of their earthly life?

Death is about life--the end of life on earth, recognizing the life that was lived, the impact it made on this world and the beginning of life eternal.
Hospice is about life in all of those ways. The following prayer evolved early in my career as a hospice chaplain.
"Almighty God, Creator of life,
and Lord Jesus Christ, giver of everlasting life through Your sacrificial work on the cross,
and Holy Spirit who lives in us so we can live an abundant life,
we thank You for life and the opportunity to live.
By living we experience love, learn knowledge,
endure suffering, enjoy pleasures, face opportunities, achieve results and make a difference.
Now at this bedside, we thank you for this precious life that mattered,
the life lived,
the life that has come into this world through them,
and the legacy of their life that will never end.
As their earthly life may soon be coming to an end
we receive all of your work for them;
your love and forgiveness,
your grace and mercy available because of your death on the cross.
I ask that you open your arms to receive them into the place you have prepared for them.
That place where there is no more sickness, sorrow, tears, pain, wars, fears, tears or good-byes.
A place where we live with you and are reunited with loved ones.
Please comfort the loved ones surrounding this bed
whose lives are now impacted by loss and grief.
Fill them with hope of everlasting life through Jesus,
in whose name I pray.
-Amen."
Hearing is often the last sense to go before a person passes. Often I have been called very near the end of someone's earthly life, when a conversation was impossible.
Before I pray this prayer over someone who is unresponsive, I always get permission from the family. Then I will say to the patient, often leaning over them, even getting close to their ear, "If you can hear me and you like what I pray, just receive it in your mind and heart. If you don't like it, ignore it and it won't make any difference."
I've had some incredible experiences from praying this prayer.
At least a handful of times the patient has passed within minutes after the prayer. It seemed they were waiting to finish their spiritual work before they could pass into their Maker's presence.
One patient who could not be comforted with medicine or touch went from seeing dark to light after this prayer.
Another time, I was called to a woman's bedside who could not be calmed and would not stop screaming,
"OH, GOD!! OH, GOD!!". Her screams were disturbing patients, visitors and staff up and down the hallway. During that prayer, her screams stopped and she became peaceful.
It is the prayer of life, to be prayed at the end of life. Hopefully you will find it useful when you care for people at the end of this earthly life.