wordpress - AngularJS - Service return value -


i've app using json user api wordpress plugin. i've service validate user cookie. first call api cookie name try validate cookie.

angular.module('app').service('authservice', authservice);  authservice.$inject = ['$http']; function authservice($http) { return {     isauthenticated: isauthenticated }; function isauthenticated(){     return $http.get('http://somesite/pcookie.php')       .then(function (response) {         var authcookiename = response.data.response;         var authcookie = getcookie(authcookiename);         var validity;                     $http.get('http://somesite/api/user/validate_auth_cookie/?cookie='+authcookie)             .then(function (response) {                 validity = response.data;               });          return validity;     }); } } 

the problems are: there other method provide logged_in_cookie cookie name? validity undefined because of nested functions. how can resolve it?

because first $http.get within isauthenticated returns promise, should instead:

function isauthenticated() {   return $http.get('http://somesite/pcookie.php')     .then(function (response) {       var authcookiename = response.data.response;       var authcookie = getcookie(authcookiename);       return authcookie;     })     .then(function (authcookie) {       return $http.get('http://somesite/api/user/validate_auth_cookie/?cookie='+authcookie);     })     .then(function (response) {       return response.data;     }); } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -