var request = require('request');

return function (ctx, cb) {
    if (!ctx.data.API_KEY)
        return cb(new Error('Missing `API_KEY` parameter.'));
    if (!ctx.data.phone)
        return cb(new Error('Missing `phone` parameter.'));

    if (ctx.data.verification_code) {
        // verify user, return profile

        return cb(new Error('Not supported yet'));
    }
    else {
        // initiate SMS verification

        request({
            url: 'https://webtask-cli.auth0.com/api/v2/users',
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': 'Bearer ' + ctx.data.API_KEY
            },
            timeout: 20000,
            body: JSON.stringify({
                phone_number: ctx.data.phone,
                connection: 'sms',
                email_verified: false
            })
        }, function (error, res, body) {
            if (error) {
                console.log('Failed to initialize SMS verification to ', ctx.data.phone, 'with error', error);
                return cb(error);
            }
            if (res.statusCode < 200 || res.statusCode > 299) {
                console.log('Failed to initialize SMS verification to ', ctx.data.phone, 'with HTTP status', res.statusCode, 'and body' + body);
                var error = new Error('Unable to initiate SMS verification.');
                error.code = res.statusCode;
                error.details = body;
                return cb(error);
            }
            try {
                body = JSON.parse(body);
            }
            catch (e) {
                console.log('Failed to initialize SMS verification to ', ctx.data.phone, 'with response body' + body);
                var error = new Error('Invalid response from Auth0.');
                error.details = body;
                return cb(error);
            }
            console.log('Initiated SMS verification ', ctx.data.phone);
            cb(null, body);
        });

    }
}
@@ -1178,35 +1178,33 @@
         
-console.log('Fai
+var msg = 'Unab
 le
-d
  to init
@@ -1197,35 +1197,33 @@
 Unable to initia
-liz
+t
 e SMS verificati
@@ -1221,33 +1221,55 @@
 erification to '
-,
+ %0A                    +
  ctx.data.phone,
@@ -1263,27 +1263,29 @@
 x.data.phone
-,
+ +
  '
+ 
 with HTTP st
@@ -1288,18 +1288,20 @@
 P status
-',
+ ' +
  res.sta
@@ -1311,190 +1311,85 @@
 Code
-, 'and body' + body);%0A                var error = new Error('Unable to initiate SMS verification.');%0A                error.code = res.statusCode;%0A                error.details = body
+ %0A                    + ' and body ' + body;%0A                console.log(msg)
 ;%0A  
@@ -1404,37 +1404,46 @@
       return cb(
-error
+new Error(msg)
 );%0A            %7D
@@ -1552,36 +1552,34 @@
             
-console.log(
+var msg = 
 'Failed to i
@@ -1601,33 +1601,34 @@
 erification to '
-,
+ +
  ctx.data.phone,
@@ -1630,147 +1630,95 @@
 hone
-, 'with response body' + body);%0A                var error = new Error('Invalid response from Auth0.');%0A                error.details = body
+ %0A                    + ' with response body ' + body;%0A                console.log(msg)
 ;%0A  
@@ -1733,37 +1733,46 @@
       return cb(
-error
+new Error(msg)
 );%0A            %7D

fix sms