The agreement expired in 2030. It did not authorize Iran to pursue nuclear weapons at that time. There's a difference.
The agreement was the best available at the time. Diplomacy sometimes requires taking a temporary win, and it usually means that neither side gets everything they want. The hope was that Iran would find that they would not want or need to develop nuclear weapons. If they did go down that path, there were penalties for doing so. Future negotiations were planned to modify or extend the agreement as it got closer to the expiration date.
That's how such agreements work. Every arms treaty signed between the US and USSR had an expiration date. The expiration date was not an agreement that at the end, both sides would immediately rearm. They were meant to establish a new normal and a baseline for future negotiations, and that's what happened. Over time, the arsenals were negotiated down from tens of thousands per side to a few thousand per side, with only a fraction of them deployed or even deployable. The last one expired a few months ago, but neither side is racing to add to their deployed warhead count.
There is no way to outright prevent Iran from developing a nuclear warhead without occupying the country and removing its entire current government. That is hundreds of billions of dollars, tens of thousands of lives, and an even worse look for the US than it has right now. Negotiating a deal like the JCPOA is the best option available. But every time Trump starts to talk about a deal and details start to leak out, they look a lot worse than the JCPOA. Trump is incompetent, he started a war that even Republicans are turning against, and he's arguably left Iran in a better place than it was before. Iran now knows that they can cut off the Strait of Hormuz, and no one can or will do anything about it. Worse, Trump has stated that he would be OK with Iran charging transit fees. If that starts, everyone else who controls a waterway that is otherwise internationally accessible is going to charge them, too. Indonesia and Malaysia would be the top two who could affect global trade, and while both have said that they would not, it's hard to say what future governments would do if they came under budget stress and had a precedent to point to.