checkExpirationOfTokens<T> static method

Future<OperationResult<T>> checkExpirationOfTokens<T>({
  1. required bool checkOnTokenExpiration,
})

Implementation

static Future<OperationResult<T>> checkExpirationOfTokens<T>(
    {required bool checkOnTokenExpiration}) async {
  if (TecfyBasicApp.checkOnTokenExpiration == true) {
    if (checkOnTokenExpiration == true) {
      if (ConfigService.token.isNotEmpty &&
          ConfigService.refreshToken.isNotEmpty) {
        bool isRefreshedSuccessfully =
            await ApiServiceHelper.assignNewTokens();

        if (!isRefreshedSuccessfully) {
          //call unauthorized callback and return OperationResult with false result
          if (IApiService.unauthrizedCallback != null) {
            IApiService.unauthrizedCallback?.call(401);
          }

          return OperationResult<T>(
              success: false, message: 'Refresh token is not valid');
        }
      }
    }
  }
  return OperationResult<T>(success: true, message: 'Token is valid');
}