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
source to share
No one has answered this question yet
Check out similar questions: