It's good that you came clean, and also posting and reading on here is a really good step to figuring out the whys for why you thought it ok to have an affair, and having so little respect and care for yourself. That's a painful path right there, but worth it.
As everyone constantly points out here, you need to dig deep to make yourself safe, not just for your BS, but for you. It's the only way to make our changes sustainable, rather than just a surface level change because of guilt or wanting to save the relationship.
You gotta want real change and growth for yourself, so you can live an authentic life rooted in self respect, truth and integrity, not bullshit, that hurts others, and yourself.
Lots of work ahead for you, for us all.