This is the way. I think this is what Apple is finally implementing, but since they took too long to do so, governments have been passing laws which require privacy invasive measures that fill the void. Hard to say if that will reverse itself now that there's a whole age-verification industry that popped up. Actually it's unclear to me if the age-verification industry manufactured a problem to push their solution?
Had Apple implemented this in their Parental Controls setting, it would have avoided the government intervention and shady age-verification companies from popping up.
Were you ever a teenager? This would be abused immediately, unless the codes were single use, and in that case it's a non-starter.