Repository navigation
Conversation
The auth keys `_authToken`, `_auth`, etc. are looked up by registry URI with an exact string match, but nothing in the docs said so. A scope that differs from the registry URL by a single trailing slash or a port is simply a different key, so npm finds no credentials at all and commands that need to log in fail with ENEEDAUTH and the generic "This command requires you to be logged in" message - the same message shown when no credentials were ever configured. Add a subsection to the auth configuration section explaining the exact-match rule, that a host-level scope is not a fallback for a path on that host, and that the ENEEDAUTH message is misleading in this case because the token is present but keyed to a non-matching URI. It also documents how to check which key npm actually resolved with `npm config get` and `npm config ls -l`. Closes: npm#3618
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a "How npm matches a credential to a registry" subsection to
configuring-npm/npmrc.md.It documents the lookup implemented in
npm-registry-fetch(lib/auth.js,regFromURI): starting from//host[:port]/pathof the registry URL, npm walks up the path until it finds a key with credentials, so host-level and shorter-path keys apply, while a different host or port never matches. It also notes that a non-matching key surfaces asENEEDAUTH/ "This command requires you to be logged in" (lib/utils/get-identity.js,lib/commands/publish.js), the same error as having no credentials at all.Scope: documentation only. This does not fix #3618 (the error message itself remains obscure); it just explains the matching rules so the error is easier to diagnose. Refs #3618 — the issue should stay open for an error-message improvement if you want one.
No tests run (docs only).
AI assistance disclosure: this change was prepared with the help of an AI coding agent (Grok Bot). The account owner has not reviewed every line in detail; please treat it accordingly.