superagent/http-transport.js
function _auth( request, options, forceAuthentication ) {
	// If we're not supposed to authenticate, don't even start
	if ( ! forceAuthentication && ! options.auth && ! options.nonce ) {
		return request;
	}

	// Enable nonce in options for Cookie authentication http://wp-api.org/guides/authentication.html
	if ( options.nonce ) {
		request.set( 'X-WP-Nonce', options.nonce );
		return request;
	}

	// Retrieve the username & password from the request options if they weren't provided
	const username = options.username;
	const password = options.password;

	// If no username or no password, can't authenticate
	if ( ! username || ! password ) {
		return request;
	}

	// Can authenticate: set basic auth parameters on the request
	return request.auth( username, password );
}
function _auth( request, options, forceAuthentication ) {
	// If we're not supposed to authenticate, don't even start
	if ( ! forceAuthentication && ! options.auth && ! options.nonce ) {
		return request;
	}

	// Enable nonce in options for Cookie authentication http://wp-api.org/guides/authentication.html
	if ( options.nonce ) {
		request.set( 'X-WP-Nonce', options.nonce );
		return request;
	}

	// Retrieve the username & password from the request options if they weren't provided
	const username = options.username;
	const password = options.password;

	// If no username or no password, can't authenticate
	if ( ! username || ! password ) {
		return request;
	}

	// Can authenticate: set basic auth parameters on the request
	return request.auth( username, password );
}
function _auth ( request , options , forceAuthentication ) { // If we're not supposed to authenticate, don't even start if ( ! forceAuthentication && ! options . auth && ! options . nonce ) { return request ; } // Enable nonce in options for Cookie authentication http://wp-api.org/guides/authentication.html if ( options . nonce ) { request . set ( 'X-WP-Nonce' , options . nonce ) ; return request ; } // Retrieve the username & password from the request options if they weren't provided const username = options . username ; const password = options . password ; // If no username or no password, can't authenticate if ( ! username || ! password ) { return request ; } // Can authenticate: set basic auth parameters on the request return request . auth ( username , password ) ; }
Conditionally set basic authentication on a server request object.

@method _auth
@private
@param {Object} request A superagent request object
@param {Object} options A WPRequest _options object
@param {Boolean} forceAuthentication whether to force authentication on the request
@param {Object} A superagent request object, conditionally configured to use basic auth
Conditionally set basic authentication on a server request object .