Skip to content

Instantly share code, notes, and snippets.

@dabit3
Last active August 17, 2016 13:33
Show Gist options
  • Save dabit3/08473fe0014cfee89caad8ca1eef3bda to your computer and use it in GitHub Desktop.
Save dabit3/08473fe0014cfee89caad8ca1eef3bda to your computer and use it in GitHub Desktop.
Ionic cordova app
this.doLogin = function(user) {
var deferred = $q.defer(),
nonce_dfd = $q.defer(),
authService = this;
authService.requestNonce("user", "generate_auth_cookie")
.then(function(nonce){
nonce_dfd.resolve(nonce);
});
nonce_dfd.promise.then(function(nonce){
//now that we have the nonce, ask for the new cookie
authService.generateAuthCookie(user.userName, user.password, nonce)
.then(function(data){
if(data.status == "error"){
// return error message
deferred.reject(data.error);
}else{
//recieve and store the user's cookie in the local storage
var user = {
cookie: data.cookie,
data: data.user,
user_id: data.user.id
};
PushNotificationsService.register();
authService.saveUser(user);
//getavatar in full size
authService.updateUserAvatar().then(function(){
deferred.resolve(user);
});
}
});
});
return deferred.promise;
};
@knolaust
Copy link

Yes. Tried that. It triggers the registration function (console logs "cordovaPushv5 initialized"). Reaches the $cordovaPushV5.initialize and fails because it can't find variable PushNotification. When that code within the PushNotificationsService is loaded on device.ready in app.js, it does not have this problem.

583191 error Error: Can't find variable: PushNotification
initialize@http://localhost:8100/lib/ngCordova/dist/ng-cordova.js:6378:32
register@http://localhost:8100/js/services.js:567:28
http://localhost:8100/js/services.js:358:44
processQueue@http://localhost:8100/lib/ionic/js/ionic.bundle.js:27879:30
http://localhost:8100/lib/ionic/js/ionic.bundle.js:27895:39
$eval@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29158:28
$digest@http://localhost:8100/lib/ionic/js/ionic.bundle.js:28969:36
$apply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29263:31
done@http://localhost:8100/lib/ionic/js/ionic.bundle.js:23676:53
completeRequest@http://localhost:8100/lib/ionic/js/ionic.bundle.js:23848:15
http://localhost:8100/lib/ionic/js/ionic.bundle.js:23758:24
callback@http://localhost:8100/lib/ionic/js/ionic.bundle.js:23879:13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment