How to handle Referer in https post reuest in ionic app with django backend?

I am new to ionic development. I am developing an ionic app with django backend. I have the code to login and register in a django project and I deploy the app to heroku.the django app heroku url works fine.

CSRFtoken settings:

angular.module('starter.controllers', ['ngCookies'])
.config(['$httpProvider', function($httpProvider ) {
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
}])

      

For login code:

$scope.doLogin = function(){
console.log($scope.loginData);
$http({
    method: 'POST',
    url: 'https://django-ionic-api-app.herokuapp.com/api/login/',
    data: $scope.loginData,
    dataType: "json"
}).then(function successCallback(response) {
    console.log(response);
    if(response.statusText == "OK"){
      alert("User login successfully!!");
      window.localStorage['userdetails'] = JSON.stringify(response.data.user);
      $scope.userdetails = JSON.parse(window.localStorage['userdetails']);
      window.location.href = $state.href('app.home');
      window.location.reload();
    }
  },function errorCallback(response) {
    console.log(response)
    alert(response.data.message)
});
};

      

Login and registration work well in a web browser. But when I confused apk and tested it on mobile, first time was successful but second time it got below error

{"detail":"CSRF Failed: Referer checking failed - no Referer."}

      

I have checked with cross-headers, but I am getting the same error. I think I need to handle this Referer error from ionic? but i dont know how to handle this from angularjs (ionic1).

Please help me, thanks.

+3
angularjs django ionic-framework


source to share


No one has answered this question yet

Check out similar questions:

595
How to make not equal in filtering Django requests?
453
How to check Django version
432
Angular directives - when and how to use compilation, controller, pre-link and post-link
315
How can I get full / absolute url (with domain) in Django?
five
Developing a mobile app with Ionic as frontend and Django as backend
1
HTTP post from Ionic 2
1
Ionic corner registration with Django backend
0
Ionic notation https
0
$ http callbackback in factory does not work when there is an infinite loop in the startup block
0
ngCordova InAppBrowser plugin freeze app on iOS, but not on Android



All Articles
Loading...
X
Show
Funny
Dev
Pics