Ionic User save fails with error "CSRF Failed: CSRF token missing or incorrect"

I’m wanting to use some of ionic.io services. Analytics appears to be working ok but I’m not able to create (save) an Ionic user from my app. I keep getting a 403 error back and the response says CSRF Failed: CSRF token missing or incorrect. I’ve mostly been working in Chrome with CORS disabled. Same thing happens when I run from the iOS sim as well. Any help or suggestions are greatly appreciated.

PUT https://apps.ionic.io/api/v1/app/<my _app_id>/users/1 403 (FORBIDDEN)
Ionic User: Error: Request Failed with status code of 403(…)

Here’s the block of code I’m trying to run. Note that the user and ionicUser already exist in the scope.

ionicUser = Ionic.User.current();
if (!ionicUser.id) {
    ionicUser.id = user.id.toString();
}
ionicUser.set('firstName', user.firstName);
ionicUser.set('lastName', user.lastName);
ionicUser.set('email', user.email);

ionicUser.save().then(function(response){
    $logger.debug('UserService.createIonicUser > ionic user ' + ionicUser.id + ' saved');
}, function(error){
    $logger.error('UserService.createIonicUser > error saving ionic user: ' + error);
});	

Here’s my ionic info:

Cordova CLI: 5.4.1
Gulp version: CLI version 3.9.0
Gulp local: Local version 3.9.0
Ionic Version: 1.2.4
Ionic CLI Version: 1.7.14
Ionic App Lib Version: 0.7.0
ios-deploy version: 1.8.4
ios-sim version: 5.0.6
OS: Mac OS X El Capitan
Node Version: v4.2.4
Xcode version: Xcode 7.2 Build version 7C68

1 Like

Did you found a solution??

Im dealing with the same problem now…

Thanks :wink:

I haven’t found a solution. I ended up commenting out the call and started using Mixpanel for analytics.

I dont know if its late for you ir not…i hope not but i found a solution i the documentation.

All is about beta migration:

See section-user-changes

Since quite while, the ionic services have been under upgrading and one important modification is that user cant be saved without authentication first.

Literrally from doc:

"Deprecation Warning

The Ionic Platform has now moved to Beta status. Part of this change is the introduction of the Platform API and User authentication. We’ve deprecated the alpha API for the Users and Push services and will be removing them entirely in the coming months."

Hope you help! :slight_smile: