Auth0 Home Blog Docs

"passwordlessVerify" success is not returning anything.

passwordlessverify

#1

I am trying to use paswordlessVerify. My code is following:

 verifySMSCode(code, callback) {
       this.auth0.passwordlessVerify({
      connection: 'sms',
      phoneNumber: "+88" + this.shareService.getPhoneNumber(),
      verificationCode: code
    }, function (err, res) {
         if (err.statusCode==400) {
        console.log('error'+err.statusCode);
        //console.log('error'+res);
        callback(false);
        
        // Handle error
      } else{
            console.log("if no error, return true"+err.statusCode);
        callback(true);
      }
      // If successful, save the user's token and proceed
    })
    return true   
  }

Now if I give valid SMS code, it never goes to else block.
Please help.

Sakib


#2

It looks like you might be using an older version of Auth0.js. In the latest version 9, you should be using the webAuth.passwordlessStart and webAuth.passwordlessLogin methods to get an sms code and verify that code, respectively.

After initializing the webAuth object with:

var webAuth = new auth0.WebAuth({
  clientID: '{YOUR_CLIENT_ID}',
  domain: '{YOUR_AUTH0_DOMAIN}',
  redirectUri: 'http://example.com',
  responseType: 'token'
});

You can trigger an sms with:

webAuth.passwordlessStart({
    connection: 'sms',
    send: 'code',
    phoneNumber: '{PHONE NUMBER}'
  }, function (err,res) {
    // handle errors or continue
  }
);

When the sms with the code is received, you’ll be able to verify it with:

webAuth.passwordlessLogin({
    connection: 'sms',
    phoneNumber: '{PHONE NUMBER}',
    verificationCode: '{CODE}'
  }, function (err,res) {
    // handle errors or continue
  }
);

You can read more about the passwordless login here:
https://auth0.com/docs/libraries/auth0js/v9#passwordless-login
https://auth0.com/docs/connections/passwordless/spa-sms/v9
https://auth0.com/docs/connections/passwordless/regular-web-app-sms/v9


#3

Thank you! Can you say how to disable redirect? Currently I am implementing a mobile app. After authentication, it opens browser. Is it possible to not redirect to browser?