Browse Source

Fix `--token` support

Closes #499
Closes #474
Closes #484
master
Matheus Fernandes 8 years ago
parent
commit
8b306e657b
No known key found for this signature in database GPG Key ID: DD07CA4EA7B65C4F
  1. 4
      bin/now-alias.js
  2. 4
      bin/now-billing.js
  3. 4
      bin/now-certs.js
  4. 4
      bin/now-deploy.js
  5. 4
      bin/now-dns.js
  6. 4
      bin/now-domains.js
  7. 4
      bin/now-list.js
  8. 4
      bin/now-logs.js
  9. 4
      bin/now-open.js
  10. 4
      bin/now-remove.js
  11. 4
      bin/now-scale.js
  12. 4
      bin/now-secrets.js
  13. 10
      bin/now-teams.js
  14. 4
      bin/now-upgrade.js
  15. 7
      bin/teams/add.js
  16. 9
      bin/teams/invite.js
  17. 4
      bin/teams/switch.js
  18. 8
      lib/cfg.js

4
bin/now-alias.js

@ -104,11 +104,11 @@ if (argv.help) {
exit(0)
} else {
Promise.resolve().then(async () => {
const config = await cfg.read()
const config = await cfg.read({token: argv.token})
let token
try {
token = argv.token || config.token || (await login(apiUrl))
token = config.token || (await login(apiUrl))
} catch (err) {
error(`Authentication error – ${err.message}`)
exit(1)

4
bin/now-billing.js

@ -90,11 +90,11 @@ if (argv.help || !subcommand) {
exit(0)
} else {
Promise.resolve().then(async () => {
const config = await cfg.read()
const config = await cfg.read({token: argv.token})
let token
try {
token = argv.token || config.token || (await login(apiUrl))
token = config.token || (await login(apiUrl))
} catch (err) {
error(`Authentication error – ${err.message}`)
exit(1)

4
bin/now-certs.js

@ -83,11 +83,11 @@ if (argv.help || !subcommand) {
exit(0)
} else {
Promise.resolve().then(async () => {
const config = await cfg.read()
const config = await cfg.read({token: argv.token})
let token
try {
token = argv.token || config.token || (await login(apiUrl))
token = config.token || (await login(apiUrl))
} catch (err) {
error(`Authentication error – ${err.message}`)
exit(1)

4
bin/now-deploy.js

@ -200,7 +200,7 @@ if (deploymentName || wantsPublic) {
let alwaysForwardNpm
Promise.resolve().then(async () => {
let config = await cfg.read()
let config = await cfg.read({token: argv.token})
alwaysForwardNpm = config.forwardNpm
if (argv.h || argv.help) {
@ -209,7 +209,7 @@ Promise.resolve().then(async () => {
} else if (argv.v || argv.version) {
console.log(version)
process.exit(0)
} else if (!(argv.token || config.token) || shouldLogin) {
} else if (!config.token || shouldLogin) {
let token
try {
token = await login(apiUrl)

4
bin/now-dns.js

@ -77,11 +77,11 @@ if (argv.help || !subcommand) {
exit(0)
} else {
Promise.resolve().then(async () => {
const config = await cfg.read()
const config = await cfg.read({token: argv.token})
let token
try {
token = argv.token || config.token || (await login(apiUrl))
token = config.token || (await login(apiUrl))
} catch (err) {
error(`Authentication error – ${err.message}`)
exit(1)

4
bin/now-domains.js

@ -119,11 +119,11 @@ if (argv.help || !subcommand) {
exit(0)
} else {
Promise.resolve().then(async () => {
const config = await cfg.read()
const config = await cfg.read({token: argv.token})
let token
try {
token = argv.token || config.token || (await login(apiUrl))
token = config.token || (await login(apiUrl))
} catch (err) {
error(`Authentication error – ${err.message}`)
exit(1)

4
bin/now-list.js

@ -68,11 +68,11 @@ if (argv.config) {
}
Promise.resolve().then(async () => {
const config = await cfg.read()
const config = await cfg.read({token: argv.token})
let token
try {
token = argv.token || config.token || (await login(apiUrl))
token = config.token || (await login(apiUrl))
} catch (err) {
error(`Authentication error – ${err.message}`)
process.exit(1)

4
bin/now-logs.js

@ -98,11 +98,11 @@ if (maybeURL(deploymentIdOrURL)) {
Promise.resolve()
.then(async () => {
const config = await cfg.read()
const config = await cfg.read({token: argv.token})
let token
try {
token = argv.token || config.token || login(apiUrl)
token = config.token || login(apiUrl)
} catch (err) {
error(`Authentication error – ${err.message}`)
process.exit(1)

4
bin/now-open.js

@ -62,11 +62,11 @@ if (argv.config) {
}
Promise.resolve().then(async () => {
const config = await cfg.read()
const config = await cfg.read({token: argv.token})
let token
try {
token = argv.token || config.token || (await login(apiUrl))
token = config.token || (await login(apiUrl))
} catch (err) {
error(`Authentication error – ${err.message}`)
process.exit(1)

4
bin/now-remove.js

@ -77,11 +77,11 @@ if (argv.config) {
}
Promise.resolve().then(async () => {
const config = await cfg.read()
const config = await cfg.read({token: argv.token})
let token
try {
token = (await argv.token) || config.token || login(apiUrl)
token = config.token || login(apiUrl)
} catch (err) {
error(`Authentication error – ${err.message}`)
process.exit(1)

4
bin/now-scale.js

@ -81,11 +81,11 @@ if (argv.help) {
exit(0)
} else {
Promise.resolve().then(async () => {
const config = await cfg.read()
const config = await cfg.read({token: argv.token})
let token
try {
token = argv.token || config.token || (await login(apiUrl))
token = config.token || (await login(apiUrl))
} catch (err) {
error(`Authentication error – ${err.message}`)
exit(1)

4
bin/now-secrets.js

@ -87,11 +87,11 @@ if (argv.help || !subcommand) {
exit(0)
} else {
Promise.resolve().then(async () => {
const config = await cfg.read()
const config = await cfg.read({token: argv.token})
let token
try {
token = argv.token || config.token || (await login(apiUrl))
token = config.token || (await login(apiUrl))
} catch (err) {
error(`Authentication error – ${err.message}`)
exit(1)

10
bin/now-teams.js

@ -85,11 +85,11 @@ if (argv.help || !subcommand) {
exit(0)
} else {
Promise.resolve().then(async () => {
const config = await cfg.read()
const config = await cfg.read({token: argv.token})
let token
try {
token = argv.token || config.token || (await login(apiUrl))
token = config.token || (await login(apiUrl))
} catch (err) {
error(`Authentication error – ${err.message}`)
exit(1)
@ -115,17 +115,17 @@ async function run({ token, config: { currentTeam } }) {
switch (subcommand) {
case 'switch':
case 'change': {
await require(resolve(__dirname, 'teams', 'switch.js'))(teams, args)
await require(resolve(__dirname, 'teams', 'switch.js'))({teams, args, token})
break
}
case 'add':
case 'create': {
await require(resolve(__dirname, 'teams', 'add.js'))(teams)
await require(resolve(__dirname, 'teams', 'add.js'))({teams, token})
break
}
case 'invite': {
await require(resolve(__dirname, 'teams', 'invite.js'))(teams, args)
await require(resolve(__dirname, 'teams', 'invite.js'))({teams, args, token})
break
}

4
bin/now-upgrade.js

@ -80,11 +80,11 @@ if (argv.help) {
exit(0)
} else {
Promise.resolve().then(async () => {
const config = await cfg.read()
const config = await cfg.read({token: argv.token})
let token
try {
token = argv.token || config.token || (await login(apiUrl))
token = config.token || (await login(apiUrl))
} catch (err) {
error(`Authentication error – ${err.message}`)
exit(1)

7
bin/teams/add.js

@ -34,7 +34,7 @@ function gracefulExit() {
const teamUrlPrefix = rightPad('Team URL', 14) + chalk.gray('zeit.co/')
const teamNamePrefix = rightPad('Team Name', 14)
module.exports = async function(teams) {
module.exports = async function({teams, token}) {
let slug
let team
let elapsed
@ -118,7 +118,10 @@ module.exports = async function(teams) {
await cfg.merge({ currentTeam: team })
stopSpinner()
await require('./invite')(teams, [], {
await require('./invite')({
teams,
args: [],
token,
introMsg: 'Invite your team mates! When done, press enter on an empty field',
noopMsg: `You can invite team mates later by running ${cmd('now teams invite')}`
})

9
bin/teams/invite.js

@ -60,12 +60,13 @@ function emailAutoComplete(value, teamSlug) {
return false
}
module.exports = async function(
module.exports = async function({
teams,
args,
{ introMsg, noopMsg = 'No changes made' } = {}
) {
const { user, currentTeam } = await cfg.read()
token,
introMsg, noopMsg = 'No changes made'
} = {}) {
const { user, currentTeam } = await cfg.read({token})
domains.push(user.email.split('@')[1])

4
bin/teams/switch.js

@ -15,10 +15,10 @@ async function updateCurrentTeam({ cfg, newTeam } = {}) {
await cfg.merge({ currentTeam: newTeam })
}
module.exports = async function(teams, args) {
module.exports = async function({teams, args, token}) {
let stopSpinner = wait('Fetching teams')
const list = (await teams.ls()).teams
let { user, currentTeam } = await cfg.read()
let { user, currentTeam } = await cfg.read({token})
const accountIsCurrent = !currentTeam
stopSpinner()

8
lib/cfg.js

@ -39,13 +39,15 @@ function save(data) {
* @return {Object}
*/
async function read({ force = false, token, apiUrl } = {}) {
let existing = null
let existing = {}
try {
existing = fs.readFileSync(file, 'utf8')
existing = JSON.parse(existing)
} catch (err) {}
if (!existing && force && token) {
// Will happen if `force`d or if `--token` is used and it's different from
// The one that's stored (which can be `undefined`)
if ((force && token) || (token && token !== existing.token) ) {
const user = await getUser({ token, apiUrl })
if (user) {
return {
@ -60,7 +62,7 @@ async function read({ force = false, token, apiUrl } = {}) {
return {}
}
if (!existing) {
if (!existing.token) {
return {}
}

Loading…
Cancel
Save