Ionic dont save user token


#1

Hi there,
I want to add a device token to an user in my app. I have the device
token, I have the user, but I cant add the token to the user despite
read a lot of documentation about the issue.

Anyone can help me please?

Here is the code, thanks

`var io = Ionic.io();

username = localStorage.getItem('username');


var signupSuccess = function(user) {
  // user was authenticated, you can get the authenticated user

  console.log(user);

};

var signupFailure = function(errors) {
  for (var err in errors) {
    // check the error and provide an appropriate message
    // for your application
    console.log(err);
    user = Ionic.User.current();
    console.log(user);
  }
};
var details = {

  'email': 'email@gmail.com',
  'password': 'pass2',
  'username':'username'
}


Ionic.Auth.signup(details).then(signupSuccess, signupFailure);

var push = new Ionic.Push();
var user = Ionic.User.current();
console.log('USER',user);

var callback = function(pushToken) {


  console.log('Registered tokens:', pushToken.token);

  alert('TOKEN: '+pushToken.token);

  user.addPushToken(pushToken);

  user.save(); // you NEED to call a save after you add the token

}

push.register(callback);`

#2

Some SO links say you have to add token to user like this push.addTokenToUser(user); in your register callback.

Also double check if you included ‘ionic.service.push’ in your app.js


#3

Is not addTokenToUser method deprecated right now in beta ? http://docs.ionic.io/docs/migration-guide


#4

You are right. It is deprecated.


#5

From the migration guide, looks like its no longer needed to add the pushToken to the user.

You now no longer add device tokens via the User object – see the push changes below.

They say this link has the entire overview of the new push