Skip to content

[BUG] npm whoami allow empty username #5867

Closed
@sosoba

Description

@sosoba

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

npm whoami

undefined

// No username, but we have other credentials; fetch the username from registry
if (creds.token || creds.certfile && creds.keyfile) {
const registryData = await npmFetch.json('/-/whoami', { ...opts })
return registryData.username
}
// At this point, even if they have a credentials object, it doesn't have a
// valid token.
throw Object.assign(
new Error('This command requires you to be logged in.'),

Expected Behavior

npm whoami

npm ERR! This command requires you to be logged in.

It seems to me, that there should be condition on return at line 15

if (registryData?.username) {
  return registryData.username;
}

Steps To Reproduce

  1. Config registry=https://verdaccio.example.com
  2. Run 'npm whoami'
  3. See result

Environment

  • npm: 8.19.2
  • Node.js: 18.12.1
  • OS Name: Windows 11
  • System Model Name: Other
  • npm config:
registry=https://verdaccio.example.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions