doRequestAuthentication<T> method

FutureOr<APIResponse<T>> doRequestAuthentication<T>(
  1. APIRequest request
)

Implementation

FutureOr<APIResponse<T>> doRequestAuthentication<T>(APIRequest request) {
  var response = APIResponse<T>.unauthorized(payloadDynamic: 'UNAUTHORIZED');
  response.startMetric('authentication');

  return authenticateByRequest(request, allowLogout: true)
      .then((authentication) {
    response.stopMetric('authentication');

    if (authentication == null) {
      return response;
    }

    T payload;
    if (T == APIAuthentication) {
      payload = authentication as T;
    } else {
      payload = authentication.toJson() as T;
    }

    return response.asOk(payload: payload);
  });
}