{"record":{"id":"c64a846a5a206c2a","repo":"nodejs/node","slug":"opts-auth-cannot-be-used-in-combination-with-opts","errorCode":null,"errorMessage":"opts.auth cannot be used in combination with opts.token","messagePattern":"opts\\.auth cannot be used in combination with opts\\.token","errorType":"exception","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/dispatcher/proxy-agent.js","lineNumber":135,"sourceCode":"    if (typeof clientFactory !== 'function') {\n      throw new InvalidArgumentError('Proxy opts.clientFactory must be a function.')\n    }\n\n    const { proxyTunnel, connectTimeout } = opts\n\n    super()\n\n    const url = this.#getUrl(opts)\n    const { href, origin, port, protocol, username, password, hostname: proxyHostname } = url\n\n    this[kProxy] = { uri: href, protocol }\n    this[kRequestTls] = opts.requestTls\n    this[kProxyTls] = opts.proxyTls\n    this[kProxyHeaders] = opts.headers || {}\n    this[kTunnelProxy] = proxyTunnel\n\n    if (opts.auth && opts.token) {\n      throw new InvalidArgumentError('opts.auth cannot be used in combination with opts.token')\n    } else if (opts.auth) {\n      /* @deprecated in favour of opts.token */\n      this[kProxyHeaders]['proxy-authorization'] = `Basic ${opts.auth}`\n    } else if (opts.token) {\n      this[kProxyHeaders]['proxy-authorization'] = opts.token\n    } else if (username && password) {\n      this[kProxyHeaders]['proxy-authorization'] = `Basic ${Buffer.from(`${decodeURIComponent(username)}:${decodeURIComponent(password)}`).toString('base64')}`\n    } else if (username) {\n      this[kProxyHeaders]['proxy-authorization'] = `Basic ${Buffer.from(`${decodeURIComponent(username)}:`).toString('base64')}`\n    }\n\n    const connect = buildConnector({ timeout: connectTimeout, ...opts.proxyTls })\n    const connectHTTP1 = buildConnector({ timeout: connectTimeout, ...opts.proxyTls, allowH2: false })\n    this[kConnectEndpoint] = buildConnector({ timeout: connectTimeout, ...opts.requestTls })\n    this[kConnectEndpointHTTP1] = buildConnector({ timeout: connectTimeout, ...opts.requestTls, allowH2: false })\n\n    const agentFactory = opts.factory || defaultAgentFactory\n    const factory = (origin, options) => {","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/dispatcher/proxy-agent.js#L117-L153","documentation":"Thrown by the ProxyAgent constructor when both opts.auth and opts.token are supplied. Both encode Proxy-Authorization credentials (auth as a pre-base64 Basic value, token as a raw header value), so providing both is ambiguous and rejected. The library wants exactly one credential source to avoid silently preferring one over the other.","triggerScenarios":"Passing { uri, auth: 'dXNlcjpwYXNz', token: 'Bearer xyz' } together; merging two config sources where one set auth and another set token; migrating from the deprecated auth to token without removing the old field.","commonSituations":"Layered config (defaults + overrides) that accidentally sets both; copy-paste between examples using different credential options; deprecated auth left in place after adding token.","solutions":["Use exactly one of opts.auth (deprecated, Basic) or opts.token (raw header value).","Prefer opts.token going forward since auth is deprecated.","Strip auth from shared/default config before adding token.","Validate that not both keys are set in your config loader."],"exampleFix":"// before\nnew ProxyAgent({ uri, auth: creds, token: tok })\n// after\nnew ProxyAgent({ uri, token: tok })","handlingStrategy":"validation","validationCode":"if (cfg.auth && cfg.token) {\n  throw new Error('Provide either auth or token, not both')\n}\nnew ProxyAgent({ uri, auth: cfg.auth, token: cfg.token })","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer token over the deprecated auth.","When merging config layers, delete the deprecated key once token is set.","Validate mutually-exclusive credential keys in your config schema."],"tags":["undici","proxy","proxy-agent","auth","invalid-arg"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}