Is there a way to detect the SIM phone number on a mobile device while using Meteor? Moreover, what is the correct behavior to have and precautions to make to log users using their phone number (like in Whatsapp or Viber for example)?
Thank you in advance.
If you're talking about a Meteor application on the web which you will access with your phone's browser, then the answer is NO (see atmd's answer)
If you're talking about a hybrid app built with Cordova i.e. meteor run android
, then YES it's possible
If you want to go quicker, I coded an example Meteor app: https://github.com/Erdou/meteor-cordova-phonenumber-example
$ meteor add-platform android
There is no plugin ready for Meteor, so you need to it manually. We will use this one here: https://github.com/rotorgames/phonegap-telephonenumber-plugin
$ meteor add cordova:[a plugin name]@[.git path]#[commit hash]
In our case:
$ meteor add cordova:cordova-plugin-phonenumber@https://github.com/rotorgames/phonegap-telephonenumber-plugin.git#ca0f55481fe8ea61e7857e96c1324591596271ee
if (Meteor.isCordova) {
TelephoneNumber.get(function(result) {
console.log('Phone number: ' + result.line1Number);
}, function() {
console.log('Error. Do the phone have this feature? (Settings > About Phone > SIM > Number)');
});
}
$ meteor run android
It should work! :)
As atmd said, using this feature is not recommended. If you want to know user's phone number, the best will be the implement the classical SMS sending / confirmation used by Viber or WhatsApp as you kind of guessed it.
I didn't test it, but there is even a Meteor package for that: https://github.com/DispatchMe/meteor-accounts-sms