interceptUnary<Q, R> method

  1. @override
ResponseFuture<R> interceptUnary<Q, R>(
  1. ClientMethod<Q, R> method,
  2. Q request,
  3. CallOptions options,
  4. ClientUnaryInvoker<Q, R> invoker,
)

Adds the access token to the gRPC call's metadata if the token is present.

Implementation

@override
ResponseFuture<R> interceptUnary<Q, R>(
  ClientMethod<Q, R> method,
  Q request,
  CallOptions options,
  ClientUnaryInvoker<Q, R> invoker,
) {
  Future<void> addAccessToken(Map<String, String> metadata, String _) async {
    final token = await _getAccessToken();
    if (token != null) {
      metadata['access_token'] = token;
    }
  }

  return invoker(
    method,
    request,
    options.mergedWith(CallOptions(providers: [addAccessToken])),
  );
}