Skip to content

Instantly share code, notes, and snippets.

@abhitheawesomecoder
Created September 9, 2018 17:05
Show Gist options
  • Save abhitheawesomecoder/d950e30e900b49dc7972072aadb10eb5 to your computer and use it in GitHub Desktop.
Save abhitheawesomecoder/d950e30e900b49dc7972072aadb10eb5 to your computer and use it in GitHub Desktop.
loginUser(){
const _this = this
let formData = new FormData();
const { country_code, email, phone_number } = this.state
const url = "https://api.authy.com/protected/json/users/new?user[email]="+email+"&user[cellphone]="+phone_number+"&user[country_code]="+country_code+"&send_install_link_via_sms=false"
fetch(url,{
method: 'POST',
headers: {
'X-Authy-API-Key': '4936D0XWwTtjJaMGmboOaytduK43FMTu'
}
})
.then((resp) => resp.json())
.then(function(data) {
//console.warn(data);
if(data.success){
_this.setState({ authyID : data.user.id, screenNo: 2 })
}else{
_this.setState({ error: true, message: "Please enter valid email and phone no."})
}
})
.catch(function(error) {
//console.warn(error);
});
}
verifyCode(){
const _this = this
const { authyID, code } = this.state
const url = "https://api.authy.com/protected/json/verify/"+code+"/"+authyID
fetch(url,{
method: 'GET',
headers: {
'X-Authy-API-Key': '4936D0XWwTtjJaMGmboOaytduK43FMTu'
}
})
.then((resp) => resp.json())
.then(function(data) {
//console.warn(data);
if(data.success){
_this.setState({ error: false,message : "Verification successfull" })
}else{
_this.setState({ error: true, message: "Please enter valid code"})
}
})
.catch(function(error) {
//console.warn(error);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment