ContextProvider typedef

ContextProvider = FutureOr<Map<String, dynamic>> Function(RequestData request)

Builds the action context for a request, typically from auth headers.

What it returns becomes the action context (ctx.context in the action). Throwing rejects the request before the action runs: a GenkitException is answered with its own status (e.g. UNAUTHENTICATED becomes 401), anything else with 403 PERMISSION_DENIED.

Future<Map<String, dynamic>> bearerAuth(RequestData request) async {
  final user = await verifyToken(request.headers['authorization']);
  if (user == null) {
    throw GenkitException('Unauthorized', status: StatusCode.unauthenticated);
  }
  return {'userId': user.id};
}

Implementation

typedef ContextProvider =
    FutureOr<Map<String, dynamic>> Function(RequestData request);