Integrations

Next.js middleware or per-route?

Example Written by the BuildAPI team to answer a common question.
BT
BuildAPI team
Example
Question

Where do people put the verify call in a Next app? Middleware feels right but I don't want to add a network round trip to every page.

BT
BuildAPI team
Example

Middleware, but cache the answer. The verify response carries an entitlement token that's good for several days — hold that, and you're only calling out when it's near expiry rather than on every request.

That's also what keeps your site up if BuildAPI is unreachable: the remembered answer stands until the token's grace runs out.

BT
BuildAPI team
Example

Entitlement token was the piece I'd skipped. That solves both problems at once.