Learn how to use the Allow List Middleware to check whether a user is allowed to use your Frames.js Frames based on their Farcaster data.
Get Started
First, install the Airstack Frames SDK:
npminstall@airstack/frames
yarnadd@airstack/frames
pnpminstall@airstack/frames
buninstall@airstack/frames
Check User's Farcaster Followers Count
You can use the allowListFramesjsMiddleware to check if a user has certain number of followers by using the NUMBER_OF_FARCASTER_FOLLOWERS and specifying the criteria using one of the comparison operator offered by Airstack:
import { createFrames, Button } from"frames.js/next";import { AllowListCriteriaEnum as AllowListCriteria, allowListFramesjsMiddleware as allowList,} from"@airstack/frames";constframes=createFrames();consthandleRequest=frames(async (ctx) => {// Use `ctx.isAllowed` to check if user is allowed or not// based on the Farcaster followers countconsole.log(ctx.isAllowed);return { image: (<div></div>), buttons: [], }; }, { middleware: [// Allow List MiddlewareallowList({ apiKey:process.env.AIRSTACK_API_KEYasstring, criteria: { or: [// Only allow those with greater than 100 followers [AllowListCriteria.NUMBER_OF_FARCASTER_FOLLOWERS, { _gte:100 }], ], }, }), ], });
const { createFrames,Button } =require("frames.js/next");const {typeAllowListCriteriaEnumasAllowListCriteria,allowListFramesjsMiddlewareasallowList,} =require("@airstack/frames");constframes=createFrames();consthandleRequest=frames(async (ctx) => {// Use `ctx.isAllowed` to check if user is allowed or not// based on the Farcaster followers countconsole.log(ctx.isAllowed);return { image: (<div></div>), buttons: [], }; }, { middleware: [// Allow List MiddlewareallowList({ apiKey:process.env.AIRSTACK_API_KEY, criteria: { or: [// Only allow those with greater than 100 followers [AllowListCriteria.NUMBER_OF_FARCASTER_FOLLOWERS, { _gte:100 }], ], }, }), ], });
true
Check If User Is Followed By Certain Farcaster User
You can use the allowListFramesjsMiddleware to check if a user is followed by a certain Farcaster user by using the FARCASTER_FOLLOWED_BY and specifying the fid of that certain Farcaster user:
import { createFrames, Button } from"frames.js/next";import { AllowListCriteriaEnum as AllowListCriteria, allowListFramesjsMiddleware as allowList,} from"@airstack/frames";constframes=createFrames();consthandleRequest=frames(async (ctx) => {// Use `ctx.isAllowed` to check if user is allowed or not// based on the Farcaster followers countconsole.log(ctx.isAllowed);return { image: (<div></div>), buttons: [], }; }, { middleware: [// Allow List MiddlewareallowList({ apiKey:process.env.AIRSTACK_API_KEYasstring, criteria: { or: [// Only allow those who are followed by fid 1 [AllowListCriteria.FARCASTER_FOLLOWED_BY, { fid:1 }], ], }, }), ], });
const { createFrames,Button } =require("frames.js/next");const {typeAllowListCriteriaEnumasAllowListCriteria,allowListFramesjsMiddlewareasallowList,} =require("@airstack/frames");constframes=createFrames();consthandleRequest=frames(async (ctx) => {// Use `ctx.isAllowed` to check if user is allowed or not// based on the Farcaster followers countconsole.log(ctx.isAllowed);return { image: (<div></div>), buttons: [], }; }, { middleware: [// Allow List MiddlewareallowList({ apiKey:process.env.AIRSTACK_API_KEY, criteria: { or: [// Only allow those who are followed by fid 1 [AllowListCriteria.FARCASTER_FOLLOWED_BY, { fid:1 }], ], }, }), ], });
true
Check If User Is Following Certain Farcaster User
You can use the allowListFramesjsMiddleware to check if a user is following a certain Farcaster user by using the FARCASTER_FOLLOWED_BY and specifying the fid of that certain Farcaster user:
import { createFrames, Button } from"frames.js/next";import { AllowListCriteriaEnum as AllowListCriteria, allowListFramesjsMiddleware as allowList,} from"@airstack/frames";constframes=createFrames();consthandleRequest=frames(async (ctx) => {// Use `ctx.isAllowed` to check if user is allowed or not// based on the Farcaster followers countconsole.log(ctx.isAllowed);return { image: (<div></div>), buttons: [], }; }, { middleware: [// Allow List MiddlewareallowList({ apiKey:process.env.AIRSTACK_API_KEYasstring, criteria: { or: [// Only allow those who are following fid 1 [AllowListCriteria.FARCASTER_FOLLOWING, { fid:1 }], ], }, }), ], });
const { createFrames,Button } =require("frames.js/next");const {typeAllowListCriteriaEnumasAllowListCriteria,allowListFramesjsMiddlewareasallowList,} =require("@airstack/frames");constframes=createFrames();consthandleRequest=frames(async (ctx) => {// Use `ctx.isAllowed` to check if user is allowed or not// based on the Farcaster followers countconsole.log(ctx.isAllowed);return { image: (<div></div>), buttons: [], }; }, { middleware: [// Allow List MiddlewareallowList({ apiKey:process.env.AIRSTACK_API_KEY, criteria: { or: [// Only allow those who are following fid 1 [AllowListCriteria.FARCASTER_FOLLOWING, { fid:1 }], ], }, }), ], });
true
Check If User Is Following The Caster
You can use the allowListFramesjsMiddleware to check if a user is following the caster of the Frame by using the FARCASTER_FOLLOWING_CASTER:
import { createFrames, Button } from"frames.js/next";import { AllowListCriteriaEnum as AllowListCriteria, allowListFramesjsMiddleware as allowList,} from"@airstack/frames";constframes=createFrames();consthandleRequest=frames(async (ctx) => {// Use `ctx.isAllowed` to check if user is allowed or not// based on the Farcaster followers countconsole.log(ctx.isAllowed);return { image: (<div></div>), buttons: [], }; }, { middleware: [// Allow List MiddlewareallowList({ apiKey:process.env.AIRSTACK_API_KEYasstring, criteria: { or: [// Only allow those who are following the caster [AllowListCriteria.FARCASTER_FOLLOWING_CASTER], ], }, }), ], });
const { createFrames,Button } =require("frames.js/next");const {typeAllowListCriteriaEnumasAllowListCriteria,allowListFramesjsMiddlewareasallowList,} =require("@airstack/frames");constframes=createFrames();consthandleRequest=frames(async (ctx) => {// Use `ctx.isAllowed` to check if user is allowed or not// based on the Farcaster followers countconsole.log(ctx.isAllowed);return { image: (<div></div>), buttons: [], }; }, { middleware: [// Allow List MiddlewareallowList({ apiKey:process.env.AIRSTACK_API_KEY, criteria: { or: [// Only allow those who are following the caster [AllowListCriteria.FARCASTER_FOLLOWING_CASTER], ], }, }), ], });
true
Developer Support
If you have any questions or need help regarding building Farcaster Frames with Airstack Frames.js Middleware, please join our Airstack's Telegram group.