|
|
@ -13,7 +13,7 @@ import pkg from '../../package' |
|
|
|
import ua from './ua' |
|
|
|
import * as cfg from './cfg' |
|
|
|
|
|
|
|
async function getVerificationToken(url, email) { |
|
|
|
async function getVerificationData(url, email) { |
|
|
|
const tokenName = `Now CLI ${os.platform()}-${os.arch()} ${pkg.version} (${os.hostname()})` |
|
|
|
const data = JSON.stringify({email, tokenName}) |
|
|
|
const res = await fetch(`${url}/now/registration`, { |
|
|
@ -31,7 +31,7 @@ async function getVerificationToken(url, email) { |
|
|
|
} |
|
|
|
|
|
|
|
const body = await res.json() |
|
|
|
return body.token |
|
|
|
return body |
|
|
|
} |
|
|
|
|
|
|
|
async function verify(url, email, verificationToken) { |
|
|
@ -61,9 +61,13 @@ async function register(url, {retryEmail = false} = {}) { |
|
|
|
return register(url, {retryEmail: true}) |
|
|
|
} |
|
|
|
|
|
|
|
const verificationToken = await getVerificationToken(url, email) |
|
|
|
const { token, securityCode } = await getVerificationData(url, email) |
|
|
|
|
|
|
|
console.log(`> Please follow the link sent to ${chalk.bold(email)} to log in.`) |
|
|
|
if (securityCode) { |
|
|
|
console.log(`> Verify that the provided security code in the email matches ${chalk.cyan(chalk.bold(securityCode))}.`) |
|
|
|
} |
|
|
|
|
|
|
|
process.stdout.write('> Waiting for confirmation..') |
|
|
|
|
|
|
|
let final |
|
|
@ -72,7 +76,7 @@ async function register(url, {retryEmail = false} = {}) { |
|
|
|
await sleep(2500) |
|
|
|
|
|
|
|
try { |
|
|
|
final = await verify(url, email, verificationToken) |
|
|
|
final = await verify(url, email, token) |
|
|
|
} catch (err) {} |
|
|
|
|
|
|
|
process.stdout.write('.') |
|
|
|