I'm new to Baasbox. I have followed the documentation and created the following below code to sign up with social login.
Here is my code of sign up with token available from respective social networks.
$scope.createUserWithBaasbox = function(t,social,isLink){
var token = t;
var headers = {'X-BAASBOX-APPCODE':1234567890}
if(isLink){
alert("entered if");
headers['X-BB-SESSION'] = auth.getToken();
}
alert("entered $apply method");
$http({
method:'POST',
headers: headers,
url: serverUrl+"/social/"+social+"?oauth_token="+token+"&oauth_secret="+token,
data:{}
}).success(function(data){
alert("success");
if(!isLink){
alert("success"+JSON.stringify(data));
var userSessionValue = data['data']['X-BB-SESSION'];
//alert(userSessionValue);
var visibleByRegisteredUsers = data['data'].visibleByRegisteredUsers;
if(visibleByRegisteredUsers.email == undefined){
alert(JSON.stringify(visibleByRegisteredUsers));
visibleByRegisteredUsers.email = data['data'].visibleByTheUser.email;
//alert(visibleByRegisteredUsers.email);
visibleByRegisteredUsers.type = "SUBSCRIBER";
visibleByRegisteredUsers.redeemedCount = 0;
visibleByRegisteredUsers.name = data['data'].visibleByTheUser.name;
visibleByRegisteredUsers.dateOfBirth = "";
visibleByRegisteredUsers.emailSubscription = true;
//alert("heyyy"+JSON.stringify(visibleByRegisteredUsers));
visibleByRegisteredUsers.shareCount = 0;
if(social == 'facebook'){
visibleByRegisteredUsers.gender = data['data'].visibleByTheUser.gender;
}
else{
visibleByRegisteredUsers.gender = "";
}
//alert(JSON.stringify(visibleByRegisteredUsers));
$http({
method:'PUT',
url: serverUrl+"/me",
data:{"visibleByRegisteredUsers" : visibleByRegisteredUsers},
headers: {'Content-Type': 'application/json',
'X-BB-SESSION' : data['data']['X-BB-SESSION']
}
}).success(function(data){
alert(data);
//TODO:local storage has to be implemented
$state.go("app.dummy");
//console.log(JSON.stringify(data));
})
.error(function(data){
alert("error block is",data);
//console.log(JSON.stringify(data));
})
}
//alert("not entered into if loop");
//TODO:local storage has to be implemented
$state.go('app.dummy');
//auth.setUser(data["data"].user,{"sso":social,"auth_token":token,"auth_secret":token},data["data"]["X-BB-SESSION"]);
//$location.path("/posts")
}
else{
//alert("loaf from exixting");
//auth.getLogins().push(social);
}
}).error(function(data){
alert("error block is:"+JSON.stringify(data));
console.log(JSON.stringify(data));
})
alert("before $scope.$apply");
}
Its executing the http method and going into the error function and returning data as " ". Can anybody help me on this?
I forgot to put
<access-origin="*">
in config.xml. So it is not allowing http requests to get response