Making locked gates/doors (C#)

I’m in need of a quick solution for making a locked gate or a door.
I have a Hinge Joint attached to the gate, but what I’d like to know is how could I make the door unable to be opened before an event has ran, and able to be opened after the event? Is there a way to sort of lock the rotation of the door until it doesn’t have to be locked anymore?

Many thanks,

A couple of things to try:

Set the isKinematic flag to true on the Rigidbody until the door can open.

Set rotation constraints on the door until the door can open.