Browse Source

Improved domain verification (#270)

New domains are no longer allowed as unverified, that allows us to
simplify `now alias` command a bit.
master
Olli Vanhoja 8 years ago
committed by Guillermo Rauch
parent
commit
213d9080b9
  1. 6
      bin/now-domains.js
  2. 21
      lib/alias.js
  3. 13
      lib/index.js

6
bin/now-domains.js

@ -225,14 +225,12 @@ async function run(token) {
const start = new Date()
const name = String(args[0])
const {uid, code, verified, verifyToken, created} = await domain.add(name, argv.force, argv.external)
const {uid, code, created, verified} = await domain.add(name, argv.force, argv.external)
const elapsed = ms(new Date() - start)
if (created && verified) {
if (created) {
console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(name))} ${chalk.dim(`(${uid})`)} added [${elapsed}]`)
} else if (verified) {
console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(name))} ${chalk.dim(`(${uid})`)} verified [${elapsed}]`)
} else if (verifyToken) {
console.log(`> Verification required: Please add the following TXT record on the external DNS server: _now.${name}: ${verifyToken}`)
} else if (code === 'not_modified') {
console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(name))} ${chalk.dim(`(${uid})`)} already exists [${elapsed}]`)
} else {

21
lib/alias.js

@ -150,19 +150,13 @@ module.exports = class Alias extends Now {
if (domainInfo.verified) {
skipDNSVerification = true
} else if (domainInfo.uid) {
const {verified, verifyToken, created} = await this.setupDomain(domain, {isExternal: true})
if (created && verified) {
console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(domain))} verified`)
} else if (verifyToken) {
const e = new Error(`> Verification required: Please add the following TXT record on the external DNS server: _now.${domain}: ${verifyToken}`)
e.userError = true
throw e
} else {
const {verified, created} = await this.setupDomain(domain, {isExternal: true})
if (!(created && verified)) {
const e = new Error(`> Failed to verify the ownership of ${domain}, please refer to 'now domain --help'.`)
e.userError = true
throw e
}
console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(domain))} verified`)
}
}
@ -227,14 +221,13 @@ module.exports = class Alias extends Now {
console.log(`> [debug] Trying to register a non-ZeitWorld domain ${domain} for the current user`)
}
const {uid, verified, verifyToken, created} = await this.setupDomain(domain, {isExternal: true})
if (created && verified) {
console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(domain))} ${chalk.dim(`(${uid})`)} added`)
} else if (verifyToken) {
const e = new Error(`> Verification required: Please add the following TXT record on the external DNS server: _now.${domain}: ${verifyToken}`)
const {uid, verified, created} = await this.setupDomain(domain, {isExternal: true})
if (!(created && verified)) {
const e = new Error(`> Failed to verify the ownership of ${domain}, please refer to 'now domain --help'.`)
e.userError = true
throw e
}
console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(domain))} ${chalk.dim(`(${uid})`)} added`)
}
console.log(`> Verification ${chalk.bold('OK')}!`)

13
lib/index.js

@ -502,18 +502,17 @@ module.exports = class Now extends EventEmitter {
err.userError = true
return bail(err)
}
// domain already exists
if (res.status === 409) {
} else if (res.status === 409) { // domain already exists
if (this._debug) {
console.log('> [debug] Domain already exists (noop)')
}
return {uid: body.error.uid, code: body.error.code}
}
if (res.status !== 200) {
} else if (res.status === 401 && body.error && body.error.code === 'verification_failed') {
const err = new Error(body.error.message)
err.userError = true
return bail(err)
} else if (res.status !== 200) {
throw new Error(body.error.message)
}

Loading…
Cancel
Save