Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
publish: Better message when an "OTP" error occurs
Browse files Browse the repository at this point in the history
PR-URL: #19580
Credit: @jdeniau
Reviewed-By: @iarna
  • Loading branch information
jdeniau authored and iarna committed Apr 12, 2018
1 parent d2d290b commit b5babf0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function upload (arg, pkg, isRetry, cached) {
if (err.code !== 'EOTP' && !(err.code === 'E401' && /one-time pass/.test(err.message))) throw err
// we prompt on stdout and read answers from stdin, so they need to be ttys.
if (!process.stdin.isTTY || !process.stdout.isTTY) throw err
return readUserInfo.otp('Enter OTP: ').then((otp) => {
return readUserInfo.otp().then((otp) => {
npm.config.set('otp', otp)
return upload(arg, pkg, isRetry, cached)
})
Expand Down
10 changes: 9 additions & 1 deletion lib/utils/read-user-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ function read (opts) {
}

function readOTP (msg, otp, isRetry) {
if (!msg) msg = 'Enter OTP: '
if (!msg) {
msg = [
'There was an error while trying authentication due to OTP (One-Time-Password).',
'The One-Time-Password is generated via applications like Authy or',
'Google Authenticator, for more information see:',
'https://docs.npmjs.com/getting-started/using-two-factor-authentication',
'Enter OTP: '
].join('\n')
}
if (isRetry && otp && /^[\d ]+$|^[A-Fa-f0-9]{64,64}$/.test(otp)) return otp.replace(/\s+/g, '')

return read({prompt: msg, default: otp || ''})
Expand Down

0 comments on commit b5babf0

Please sign in to comment.