The biggest question to ask here is when does it happen. I would try running something like Fur Mark (a free gpu stress test) which will help narrow down the possibilities somewhat.
If it does crash consistently when running furmark it's definitely a load dependent issue, and could point either to GPU or PSU. Another diagnostic tool to use during this test is CPU Z which will tell you temps and usages of everything in the system. Take note of temps in the 80°s - 90°s c, and watch if something is spiking to that temperature quickly and staying there (slowly building up to that point during a stress test is not unheard of).
If you're having trouble replicating the problem (and this is a good idea anyway) then do some sanity checks. Make absolutely sure there aren't any plugs hanging part of the way out, and that none of your fans are stopped or blocked. Another problem that can sometimes be difficult to diagnose (and that causes random shutdowns) can be a cable that is pinched tightly behind the motherboard. The metal points of solder behind your motherboard can puncture the insulation of cables that are incorrectly routed behind it and cause shorts which can cause any number of issues.
Another issue that can be difficult to diagnose, but that can also cause spontaneous shutdowns is CPU mounting pressure. Depending on the motherboard and cpu combo (some are more sensitive to this kind of issue than others, early gen ryzen in particular) the motherboard itself can actually flex and cause unexpected behaviour or damage if the cpu mounting screws are too tight. Try backing them off slightly and see if the issue persists.
Lastly try the computer on other power outlets / power strips. Many random shutdown issues aren't even the fault of the computer itself, but rather the result of a wiring issue or bad surge protector. Double check by using known good cables and outlets in other parts of the house.
It's a little bit of a long to do list, but all of these options stop short of buying parts. It is absolutely possible that you need a new power supply, and I've had to replace a few over the years myself. But I've also spent money that I later found out I didn't need to. Hopefully this saves you a few dollars and some frustration.