angularjs - Angular authentication using Passport for Ionic App -


i've built api web app, built using mean stack. trying use api on mobile client side built using ionic framework. i'm using code perform $http call api:

    $http.post(serverip+'/login', {username: $scope.credentials.username, password: $scope.credentials.password}).success(function(response) {         $scope.authentication.user = response;         $location.path('/');     }).error(function(response) {         $scope.error = response.message;     }); 

it gets valid response user object, if try info protected parts of api doesn't work , auth being reset.

on web app, use same code , works fine. issue happens on ionic app. i've set cors that:

app.use(function(req, res, next) {  res.header('access-control-allow-origin', '*');  res.header('access-control-allow-methods', 'get,put,post,delete,options');  res.header('access-control-allow-headers', 'content-type,  authorization, content-length, x-requested-with');   // intercept options method  if ('options' === req.method) {    res.sendstatus(200);  }  else {    next();  } }); 

please, me!

try adding line in angular config:

app.config(function ($httpprovider) {     $httpprovider.defaults.withcredentials = true; }); 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -