Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we verify "npm login" succeeded and the token has not expired?

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?

like image 942
Ryan Avatar asked Sep 12 '18 06:09

Ryan


People also ask

Do npm tokens expire?

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.

How do I check my npm credentials?

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.

What command will show you all your active npm security tokens?

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 .


1 Answers

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
like image 89
Juan Picado Avatar answered Sep 30 '22 19:09

Juan Picado