-
-
Notifications
You must be signed in to change notification settings - Fork 30
[SDK] Gating
Gating allows you to check different conditions in your handler before continuing further execution.
Gating is very powerful and it is very common to implement it in your template, as Users want to let only certain Viewers interact with their Frames.
FrameTrain comes with an API for gating. As a developer, to make use of it you have to let the User configure the gating options (this is done with the GatingInspector
) and then call the runGatingChecks
function in your handler.
If the Viewer doesn't pass the gating checks, the handler will not continue execution and the Viewer will get an error in the Frame about what gating condition was not met. This is done automatically by FrameTrain, see image below.
The runGatingChecks
function takes in 2 parameters:
- the validated Frame payload which you receive in every
handler
function - the gating options the User configured in the
GatingInspector
The User can configure different gating options for different Views/Handler, in order to do this you just have to store each group of gating options in its own object in the config
object.
In the below example, we are storing the gating options in the gating
key of the config
, but you can use any name you want, and you can also have multiple objects to hold gating settings, as mentioned above.
⚠️ Note: Never edit the gating options directly. Instead, use the GatingInspector
component to let the User configure them.
import { runGatingChecks } from '@/lib/gating'
export default function myHandler({
body,
config,
storage,
}: {
body: FramePayloadValidated
config: Config
storage: Storage
}): Promise<BuildFrameData> {
runGatingChecks(body, config.gating)
...
}