It’s called Voluntary Assisted Dying. Some countries have it. There’s a whole bunch of forms and assessments to be done first though. It’s been used by people with really painful conditions that keep getting worse.
Pretty sure it has to be incurable and make life too painful for someone to bear. They also have to be “of sound mind” (the same as when writing a will) but it’s actually assessed. The process can take months.
There have, for decades at least, also been unofficial ways of achieving this. My “Nanna” was in a nursing home. She refused treatment (like cleaning up and closing) for open sores on her back. She had been bed-ridden for months and no longer wanted to live. The Dr prescribed morphine for pain relief. Morphine is really powerful. The dose was gradually increased until her heart stopped one night. The morphine was for excruciating pain. A side effect was death. This happens more often than most people know, with other drugs as well.