I've got a script that verifies a user has logged into a private npm registry (via "npm login") by greping for:
//registry-sub-url:_authToken=
... in:
~/.npmrc
However, this breaks down over time as the user's credentials expire (due to standard password expiration rules).
What's more, the helper scripts I've created have cannot differentiate between successful/failed npm login
calls, since the script always exits with 0
status.
Q: (1) How do we verify that npm login
succeeded? (2) How do identify when the npm token has expired?
The tokens do not expire by time. But if the user associated with a token can no longer be found (e.g., a mapped LDAP user is no longer in the LDAP server), the token will expire.
Once you have created a user and logged in, you can use npm config ls to ensure that the credentials are stored on your client. You can also check that your user has been added to the registry by going to https://npmjs.com/~username.
npm token list : Shows a table of all active authentication tokens. You can request this as JSON with --json or tab-separated values with --parseable .
You might use npm whoami
command.
$> npm whoami
${username}
$> npm logout
npm whoami
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`
npm ERR! A complete log of this run can be found in:
npm ERR! /xxxxx/.npm/_logs/2019-02-06T10_21_10_780Z-debug.logged
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With